Amit Bisht
Amit Bisht

Reputation: 5136

How to add extra charcter in a list of string?

I had a list of strings

var li = new List<string>()
{
    "word1", "word2", "word3", "word4", "word5", "word6",
};

I want to concatinate some some character in each word output list will be will be

word1#,word2#,word3#,word4#,word5#,word6#

Upvotes: 1

Views: 80

Answers (2)

Kamil Budziewski
Kamil Budziewski

Reputation: 23087

Try this

var word = string.Join("#,",li)+"#";

It will join your strings separated with #,

Upvotes: 1

Enigmativity
Enigmativity

Reputation: 117047

How about doing this:

li = li.Select(x => x + "#").ToList();

If you mean you want to output the string "word1#,word2#,word3#,word4#,word5#,word6#", then, after the above line, do this:

var output = String.Join(",", li);

Upvotes: 4

Related Questions