Solved

Split string and return only certain values using vb.net

Posted on 2016-07-18
2
32 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
Comment Utility
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
Comment Utility
Thanks Dustin.....that will work
0

Featured Post

Why You Should Analyze Threat Actor TTPs

After years of analyzing threat actor behavior, it’s become clear that at any given time there are specific tactics, techniques, and procedures (TTPs) that are particularly prevalent. By analyzing and understanding these TTPs, you can dramatically enhance your security program.

Join & Write a Comment

Welcome my friends to the second instalment and follow-up to our Minify and Concatenate Your Scripts and Stylesheets (http://www.experts-exchange.com/Programming/Languages/.NET/ASP.NET/A_4334-Minify-and-Concatenate-Your-Scripts-and-Stylesheets.html)…
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…
In this tutorial you'll learn about bandwidth monitoring with flows and packet sniffing with our network monitoring solution PRTG Network Monitor (https://www.paessler.com/prtg). If you're interested in additional methods for monitoring bandwidt…
This tutorial demonstrates a quick way of adding group price to multiple Magento products.

772 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

10 Experts available now in Live!

Get 1:1 Help Now