Solved

Split string and return only certain values using vb.net

Posted on 2016-07-18
2
34 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
2 Comments
 
LVL 12

Accepted Solution

by:
Dustin Saunders earned 500 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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

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…
Wouldn’t it be nice if you could test whether an element is contained in an array by using a Contains method just like the one available on List objects? Wouldn’t it be good if you could write code like this? (CODE) In .NET 3.5, this is possible…
With the power of JIRA, there's an unlimited number of ways you can customize it, use it and benefit from it. With that in mind, there's bound to be things that I wasn't able to cover in this course. With this summary we'll look at some places to go…
Hi friends,  in this video  I'll show you how new windows 10 user can learn the using of windows 10. Thank you.

863 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

Need Help in Real-Time?

Connect with top rated Experts

21 Experts available now in Live!

Get 1:1 Help Now