문제

I have a list of strings and I am concatenating it to flatten out the list by using the method seen here on DotNetPerls, http://www.dotnetperls.com/string-concat

My question is...in their List example where their output is "catdogperls" (see toward the bottom of the webpage, just before the Summary) how do I insert a # sign as a separator between "catdogperls" such that it becomes "cat#dog#perls"?

도움이 되었습니까?

해결책

In this case you don't want to use string.Concat(), you want to use string.Join(). This accepts a separator and an array of strings to join by that separator. For example:

var joined = string.Join("#", theArray);

This would place the string value in joined:

"cat#dog#perls"

(assuming, of course, that theArray contains those values)

다른 팁

Try like this :

String.Join("#", catdogperls)

You're looking for String.Join(), which takes a collection and a separator.

Use string.Join(), it allows you to specify the separator you want between each string - it's been in the framework since v2.0.

In later versions of the framework it was extended so that you could pass in an IEnumerable instead of just an array.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top