Solved

Split string and return only certain values using vb.net

Posted on 2016-07-18
2
54 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 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

Turn Insights into Action

Communication across every corner of your business is essential to increase the velocity of your application delivery and support pipeline. Automate, standardize, and contextualize your communication processes with xMatters.

Question has a verified solution.

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

In my previous two articles we discussed Binary Serialization (http://www.experts-exchange.com/A_4362.html) and XML Serialization (http://www.experts-exchange.com/A_4425.html). In this article we will try to know more about SOAP (Simple Object Acces…
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…
There are cases when e.g. an IT administrator wants to have full access and view into selected mailboxes on Exchange server, directly from his own email account in Outlook or Outlook Web Access. This proves useful when for example administrator want…
There's a multitude of different network monitoring solutions out there, and you're probably wondering what makes NetCrunch so special. It's completely agentless, but does let you create an agent, if you desire. It offers powerful scalability …

696 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