문자열 끝 확인 함수
string_ends_with
함수는 주어진 문자열이 특정 하위 문자열로 끝나는지를 확인하는 기능을 제공합니다. 이 함수는 문자열이 하위 문자열로 끝나면 true
를 반환하고, 그렇지 않으면 false
를 반환합니다.
문법
string_ends_with(str, substr);
인수 설명
인수 | 타입 | 설명 |
---|---|---|
str | String | 주어진 하위 문자열로 끝나는지 확인할 문자열 |
substr | String | 문자열이 끝나야 하는 하위 문자열 |
반환값
- Boolean: 문자열이 하위 문자열로 끝나면
true
, 그렇지 않으면false
를 반환합니다.
예제
var _message = "Hello World.";
||string_ends_with(_message, "?")||
|---|---|---|
show_debug_message("The message is a valid sentence.");
}
위의 코드는 먼저 문자열을 정의하고 이를 임시 변수 _message
에 저장합니다. 그런 다음 string_ends_with
함수를 세 번 호출하여 문자열이 다음 세 가지 구두점 중 하나로 끝나는지를 확인합니다: ".", "?", "!"
. 만약 메시지가 이 중 하나로 끝나면 디버그 메시지를 표시합니다.
활용 예제
- 사용자 입력 검증
gml var user_input = "What time is it?"; if string_ends_with(user_input, "?") { show_debug_message("User input is a question."); }
- 파일 확장자 확인
gml var filename = "document.pdf"; if string_ends_with(filename, ".pdf") { show_debug_message("This is a PDF file."); }
- 명령어 확인
gml var command = "exit!"; if string_ends_with(command, "!") { show_debug_message("Exiting the program."); }
- URL 확인
gml var url = "https://example.com/"; if string_ends_with(url, "/") { show_debug_message("This URL ends with a slash."); }
- 비밀번호 확인
gml var password = "mypassword123!"; if string_ends_with(password, "!") { show_debug_message("Password is strong."); }