Join a string in C#

Posted by Akiii under C# category on | Points: 40 | Views : 1912
Hi all,
We have seen splitting a string, now we will see how to join a string. Follow the code below:-

First, take some strings in a string variable,
string str = "item1, item2, item3";

Split the string with the help of the Split method,
string[] arr = str.Split(new Char[] {','});

Take another string variable for joining purpose,
string jnstr;

The above array which contains the split strings are passed as an argument to the join function
jnstr = String.Join("-", arr);

Print the value of the variable "jnstr",

That's it, execute the code above.....

Thanks and Regards

Comments or Responses

Login to post response