How to use Join Method in VB.NET

Join method combined two or more strings or objects (elements of array) together .
  • 2114
Download Files:
 

You can combined two or more strings or objects together. It is also combine elements of array. Join Method take first separator that  divide strings. I have used two different separator. In first line, I used ":" to represent separation between two strings  and in last line "vblf" for new line. You can use any separator to represent combination of lines.

img.gif
Next, join method take name of strings that you want to combine to other string.

In the below join method str1 and str2 is joined using "," separator.
 
 Dim
joinStr = String.Join(":", str1, str2)
 
 And the below statement join only one string with separator.

 
 Dim
str3 As String = String.Join(vbLf, arr2)

 Code
 

 Module
Module1
 
    Sub Main()
         Dim str1 = "My name is"
 
        Dim str2 = "Sachin Tendulkar"
 
        Dim joinStr = String.Join(":", str1, str2)
         Console.WriteLine(joinStr)
         Dim arr2 As String() = New String()

            
{
                 "Mark"
, "Clark", "Hussey", "Lara"
            
}
         Dim str3 As String = String.Join(vbLf, arr2)
         Console.WriteLine(str3)
         Console.ReadLine()
     End Sub

 End
Module
 
 Output
 
  output.gif

Categories

More Articles

© 2019 DotNetHeaven. All rights reserved.