?
Solved

Split string and return only certain values using vb.net

Posted on 2016-07-18
2
Medium Priority
?
60 Views
Last Modified: 2016-07-18
I have a string of data that contains URL's.  Each URL in the string has a prefix.    I am spliting the string using the following:

Dim parts As String() = data.Split(New String() {"XXX:", "ZZZ:"}, StringSplitOptions.RemoveEmptyEntries)

I am able to split the string into three URL's but i only need and want the URL's that have a prefix of 'XXX'.  Is their any way to just return those two URL's?

String  being split - XXX:http://www.data.com/viewtiff?e=23721693&b=1004939030&t=23602423&rd3=105133693 XXX:http://www.data.com/viewtiff?e=23721694&b=1004939030&t=23602423&rd3=105133693 ZZZ:http://www.data.com/viewtiff?e=23704711&b=1004936046&t=23602423&rd3=105133693
0
Comment
Question by:Mike_Stevens
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
2 Comments
 
LVL 13

Accepted Solution

by:
Dustin Saunders earned 2000 total points
ID: 41717483
Here's one approach-

Split the string keeping X: or Z: and then if the string started with X: add it to an array of links.  You can test in a console app.

Dim this = "XXX:http://www.data.com/viewtiff?e=23721693&b=1004939030&t=23602423&rd3=105133693 XXX:http://www.data.com/viewtiff?e=23721694&b=1004939030&t=23602423&rd3=105133693 ZZZ:http://www.data.com/viewtiff?e=23704711&b=1004936046&t=23602423&rd3=105133693"
        Dim parts As String() = this.Split(New String() {"XX", "ZZ"}, StringSplitOptions.RemoveEmptyEntries)
        Dim links As String() = {}
        For Each part In parts
            If (part.IndexOf("X:") = 0) Then
                links = links.Concat({part.ToString().Replace("X:", "")}).ToArray
            End If
        Next
        Console.WriteLine(links(0))
        Console.WriteLine(links(1))
        Console.Read()

Open in new window

0
 

Author Comment

by:Mike_Stevens
ID: 41717561
Thanks Dustin.....that will work
0

Featured Post

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

More often than not, we developers are confronted with a need: a need to make some kind of magic happen via code. Whether it is for a client, for the boss, or for our own personal projects, the need must be satisfied. Most of the time, the Framework…
A long time ago (May 2011), I have written an article showing you how to create a DLL using Visual Studio 2005 to be hosted in SQL Server 2005. That was valid at that time and it is still valid if you are still using these versions. You can still re…
Monitoring a network: how to monitor network services and why? Michael Kulchisky, MCSE, MCSA, MCP, VTSP, VSP, CCSP outlines the philosophy behind service monitoring and why a handshake validation is critical in network monitoring. Software utilized …
Add bar graphs to Access queries using Unicode block characters. Graphs appear on every record in the color you want. Give life to numbers. Hopes this gives you ideas on visualizing your data in new ways ~ Create a calculated field in a query: …
Suggested Courses

741 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question