문자열이 −
라고 가정해 보겠습니다.string str = "Never Give Up!";
먼저 각 단어를 나눕니다 -
string[] strSplit = str.Split();
이제 각 단어를 반복하고 부분 문자열 방법을 사용하여 다음 코드와 같이 첫 번째 문자를 표시합니다 -
예
using System;
public class Program {
public static void Main() {
string str = "Never Give Up!";
Console.WriteLine("Initial String= "+str);
Console.WriteLine("Displaying first letter of each word...");
string[] strSplit = str.Split();
foreach (string res in strSplit) {
Console.Write(res.Substring(0,1));
}
}
} 출력
Initial String= Never Give Up! Displaying first letter of each word... NGU