The difference between .join and .concat?

So i am understanding these vb.net expressions but what exactly is the difference between .join and .concat?

1 Like

Hi
.concat - Will concatenate the object that is passed as input arguments al together as a single string
Syntax is
String.Concat(obj1,obj2,…,obj3)

String.Concat(“hi”,” Good Morning”)

Output will be like hi Good Morning

While
.join will concatenate the elements in array element passed with the dlelimiter mentioned in between them
Syntax is
String.Join(“delimiter we want”,Arrayvariable)
String.Join(“-“,Arrayvariable)

If Arrayvariable has value as {“1”,”2”}
The output will be like
1-2

Cheers @BjrnUitenbroek

6 Likes

@BjrnUitenbroek,

String.Join allows seperator as explicit parameter and string.Concat doesn’t have such parameter.

string.Join(seperator, stringarray[])
string.concat(stringarray[])
2 Likes

Hello @BjrnUitenbroek,

Concatenation adds two strings and join separates the strings from Array.
Module Module1
Sub Main()
’ Join array.
Dim result As String = String.Join("/", 1, 2, 3, “VB.NET”)

    ' Display result.
    Console.WriteLine(result)
End Sub

End Module

Output

1/2/3/VB.NET

1 Like

Thanks a lot @sarathi125,

But what exactly is the benefit of being able to use a seperator?

@BjrnUitenbroek,

You will get a string with the separator you have mentioned in the “Join” method.
Most of the times I use to write values into text files using
string.join(Environment.Newline, stringarray)
so it will be useful based on the needs.

1 Like

Whenever we need a Datarow or any array element altogether as a string element then we can use String.Join method with a delimiter or separator inbetween those elements in the array

For DataRow variable
The syntax will be like
String.Join(“-“,datarowvariable.ItemArray)

For array variable
String.Join(“-“,Arrayvariable)

These two will give string as a outout with those delimiter mentioned between each element in that array

Cheers @BjrnUitenbroek

1 Like

Thank you so much! @sarathi125 Have a great day!

Cheers!

Thank you so much for helping again @Palaniyappan have a great day!

Cheers!

1 Like

you too buddy
@BjrnUitenbroek

1 Like

Thanks! Happy automation! @Palaniyappan

1 Like

This topic was automatically closed 3 days after the last reply. New replies are no longer allowed.