먼저 문자열을 설정하십시오 -
string str = "Science and Mathematics";
이제 Split() 메서드를 사용하여 공백이 있는 곳을 분할합니다. -
str.Split(' ') 다음은 완전한 코드입니다 -
예시
using System;
using System.Linq;
using System.IO;
class Program {
static void Main() {
string str = "Science and Mathematics";
Console.WriteLine("String...\n"+str);
string[] myStr = str.Split(' ');
Console.WriteLine("\nSplitted String...");
foreach (string ch in myStr) {
Console.WriteLine(ch);
}
}
} 출력
String... Science and Mathematics Splitted String... Science and Mathematics