Solved

Split string and return only certain values using vb.net

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

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

This document covers how to connect to SQL Server and browse its contents.  It is meant for those new to Visual Studio and/or working with Microsoft SQL Server.  It is not a guide to building SQL Server database connections in your code.  This is mo…
This article shows how to deploy dynamic backgrounds to computers depending on the aspect ratio of display
In an interesting question (https://www.experts-exchange.com/questions/29008360/) here at Experts Exchange, a member asked how to split a single image into multiple images. The primary usage for this is to place many photographs on a flatbed scanner…

733 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