문자열에 단어가 포함되어 있는지 확인하려면 Contains() 메서드를 사용합니다.
문자열 설정 -
string s = "Together we can do so much!";
이제 "많이"라는 단어를 찾아야 한다고 가정해 보겠습니다.
if (s.Contains("much") == true) {
Console.WriteLine("Word found!");
} 전체 코드를 보자 -
예시
using System;
public class Demo {
public static void Main() {
string s = "Together we can do so much!";
if (s.Contains("much") == true) {
Console.WriteLine("Word found!");
} else {
Console.WriteLine("Word not found!");
}
}
} 출력
Word found!