Results 1 to 6 of 6

Thread: How to Join a string array?

  1. #1

    Thread Starter
    Admodistrator |2eM!x's Avatar
    Join Date
    Jan 2005
    Posts
    3,900

    How to Join a string array?

    In vb6 we could simply do Join(sourcearray, delimiter)

    But I cant find the equivalent in vb.net, Is there?
    ----

    Also, I'm writing a FireFox proxy changer, and Im looking for input on how I could improve my code:


    VB Code:
    1. Option Strict On
    2. Option Explicit On
    3.  
    4. Public Class Form1
    5.  
    6.     Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
    7.         Dim Path As String = String.Empty
    8.         Dim js_Prefs() As String
    9.         Dim RndProxy As New Random
    10.         Dim Proxies() As String = (My.Computer.FileSystem.ReadAllText(Application.StartupPath & "\Proxies.txt")).Split(CChar(Environment.NewLine))
    11.         For Each FxUserName As String In IO.Directory.GetDirectories("C:\Documents and Settings\" & Environment.UserName & "\Application Data\Mozilla\Firefox\Profiles\")
    12.             Path = FxUserName
    13.         Next
    14.         js_Prefs = My.Computer.FileSystem.ReadAllText(Path & "\prefs.js").Split(CChar(Environment.NewLine))
    15.         Dim IP As String = Proxies(RndProxy.Next(0, Proxies.GetUpperBound(0))).Trim
    16.         For I As Int32 = 0 To js_Prefs.GetUpperBound(0)
    17.             If js_Prefs(I).Contains("network.proxy.http_port") Then
    18.                 js_Prefs(I) = js_Prefs(I).Substring(1, js_Prefs(I).LastIndexOf(",") + 1)
    19.                 js_Prefs(I) += IP.Substring(IP.IndexOf(":") + 1) & ");"
    20.                 Exit For
    21.             ElseIf js_Prefs(I).Contains("network.proxy.http") Then
    22.                 js_Prefs(I) = js_Prefs(I).Substring(1, js_Prefs(I).IndexOf(",") + 1)
    23.                 js_Prefs(I) += Convert.ToChar(34) & IP.Substring(1, IP.IndexOf(":") - 1) & Convert.ToChar(34) & ");"
    24.             End If
    25.         Next
    26.     End Sub
    27.  
    28. End Class

  2. #2
    PowerPoster
    Join Date
    Aug 2005
    Location
    College Station, TX
    Posts
    4,521

    Re: How to Join a string array?

    You can just loop through the array, concatenating it...
    VB Code:
    1. Dim BigString as String
    2. For each str as string in MyStringArray()
    3.     BigString &= str & Delimiter
    4. Next
    5. Messagebox.Show(BigString)

  3. #3
    PowerPoster
    Join Date
    Mar 2002
    Location
    UK
    Posts
    4,780

    Re: How to Join a string array?

    It still exists, you can use the
    VB Code:
    1. Microsoft.VisualBasic.Strings.Join(stringthing)
    namespace to get hold of it, or better still, use the real .Net way
    VB Code:
    1. System.String.Join(" ", stringthing)

  4. #4
    PowerPoster
    Join Date
    Aug 2005
    Location
    College Station, TX
    Posts
    4,521

    Re: How to Join a string array?

    Wow Grimfort, I hadn't ever seen that Didn't even know it existed....

  5. #5
    PowerPoster
    Join Date
    Mar 2002
    Location
    UK
    Posts
    4,780

    Re: How to Join a string array?

    Oooo, as another pointer, lookup the StringBuilder class. It allows you to concat strings, much much quicker when doing a lot of looping. For a quick bit of code you can do this:

    VB Code:
    1. Dim intIndex As Integer
    2.         Dim MeBuilder As New System.Text.StringBuilder
    3.         For intIndex = 0 To 10000
    4.             MeBuilder.Append("All my test data" & vbCrLf)
    5.         Next
    6.         'Use the data
    7.         testtest = MeBuilder.ToString

  6. #6

    Thread Starter
    Admodistrator |2eM!x's Avatar
    Join Date
    Jan 2005
    Posts
    3,900

    Re: How to Join a string array?

    Thanks man it works

    system.string.join

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width