문자열의 Join() 메서드는 각 요소 사이에 지정된 구분 기호를 사용하여 문자열 배열의 모든 요소를 연결합니다.
아래 예에서 우리는 여러 줄의 문자열을 가지고 있으며 구분 기호를 "\n" −
으로 설정했습니다.String.Join("\n", starray); 예시
다음은 완전한 예입니다 -
using System;
namespace StringApplication {
class StringProg {
static void Main(string[] args) {
string[] starray = new string[]{"Down the way nights are dark",
"And the sun shines daily on the mountaintop",
"I took a trip on a sailing ship",
"And when I reached Jamaica",
"I made a stop"};
string str = String.Join("\n", starray);
Console.WriteLine(str);
}
}
} 출력
Down the way nights are dark And the sun shines daily on the mountain top I took a trip on a sailing ship And when I reached Jamaica I made a stop