Struggling to remove parts of strings in an array

Johnson

Well-known member
Joined
Mar 6, 2009
Messages
158
Programming Experience
Beginner
Hello, If i can just give a quick in site to what i am trying to do.

URL
VB.NET:
http://www.vbdotnetforums.com/editpost.php?do=editpost&p=126751]Xtreme Visual Basic Talk
Remove char and onwards
?

New URL
VB.NET:
http://www.vbdotnetforums.com/editpost.php


That may not of explained it all so i will show you my previous working example using string builder on a single instance.

VB.NET:
    Private Sub ConVertURL()
        ' Strip URL text to generate correct download link
        _sb.Append(_rtnSourceCode_LinkHolder)

        Dim idx As Integer = _sb.ToString.IndexOf(charURLToRemove)

        If idx <> -1 Then
            _sb.Remove(idx, _sb.Length - idx)
        End If

        _rtnSourceCode_LinkHolder = _sb.ToString & MuiscFormatType

    End Sub

Would return
VB.NET:
http://www.vbdotnetforums.com/editpost.php

from
VB.NET:
http://www.vbdotnetforums.com/editpost.php?do=editpost&p=126751
Talk[/url]

But now i want to do an array of items but not really sure how to.
VB.NET:
    Private Sub btnSourceOneRetrieve_Click(ByVal sender As System.Object, 
        Me.mArryLinkEntries = SoundCloud_ReplaceURLchrs()
    End Sub

    Private Function SoundCloud_ReplaceURLchrs() As List(Of String)
        ' Strip URL text to generate correct download link
        Dim arryMusicSingle As List(Of String) = Me.mArryLinkEntries
        Dim idx As Integer = _sb.ToString.IndexOf(txtSourceOneChrOffset.Text)

        _sb.Append(Me.mArryLinkEntries)

        ' Convert stored array links to downloadable format
        For Each line In arryMusicSingle
            _sb.Remove(idx, _sb.Length - idx)
        Next

        Return arryMusicSingle

    End Function

I know the above is wrong, but it was an attempt :(

any help?
 
The part after the ? in a URL is called the query string. To drop the query string from a single URL would be:
VB.NET:
url = url.Substring(0, url.IndexOf("?"c))
To do that to each element of an array would be:
VB.NET:
For index = 0 To myArray.GetUpperBound(0)
    Dim url As String = myArray(index)

    myArray(index) = url.Substring(0, url.IndexOf("?"c))
Next
Alternatively, you could create a new array:
VB.NET:
myArray = Array.ConvertAll(myArray, Function(url) url.Substring(0, url.IndexOf("?"c)))
 
You are a legend

VB.NET:
        Dim arryMusicSingle As List(Of String) = Me.mArryLinkEntries

        For x As Integer = 0 To arryMusicSingle.Count - 1
            Dim url As String = arryMusicSingle(x)
            arryMusicSingle(x) = url.Substring(0, url.IndexOf("?"c))
        Next
 
Back
Top