[Unity] 문자열 앞 뒤 부분 특정 문자열 확인 (StartsWith, EndsWith)

업데이트:

카테고리:

태그: ,


StartsWith , EndsWith



StartsWith

문자열이 특정 문자열로 시작하는지 확인합니다.
대소문자 구문, 대소문자 무시하고 싶다면 두번째 인자를 StringComparison

string s = "Unity6";

bool result = s.StartsWith("Unit");  // true
bool result2 = s.StartsWith("6"); // false

bool result = s.StartsWith("hello", StringComparison.OrdinalIgnoreCase);  // true





EndsWith

문자열이 특정 문자열로 끝나는지 확인합니다.

string s = "HelloWorld";

bool result = s.EndsWith("World");  // true
bool result2 = s.EndsWith("Hello"); // false

bool result = s.EndsWith("world", StringComparison.OrdinalIgnoreCase); // true







메모

문자열 앞 뒤 부분 특정 문자열 확인 (StartsWith, EndsWith)




📔

댓글남기기