C#에서 StartWith() 메서드를 사용하여 문자열의 URL을 확인합니다.
입력 문자열이 −
라고 가정해 보겠습니다.string input = "https://example.com/new.html";
이제 www 또는 www가 없는 링크를 확인해야 합니다. 이를 위해 C#에서 if 문을 사용하십시오 -
if (input.StartsWith("https://www.example.com") || input.StartsWith("https://example.com")) {
} 예시
다음 코드를 실행하여 문자열의 URL을 확인할 수 있습니다.
using System;
class Demo {
static void Main() {
string input = "https://example.com/new.html";
// See if input matches one of these starts.
if (input.StartsWith("https://www.example.com") || input.StartsWith("https://example.com")) {
Console.WriteLine(true);
}
}
} 출력
True