此函数用于检查字符串是否以给定子字符串结尾。如果以给定子字符串结尾,则返回 true,否则返回 false。
string_ends_with(str, substr);
参数 | 类型 | 描述 |
---|---|---|
str | String | 要检查给定子字符串在末尾是否出现的字符串 |
substr | String | 字符串结尾的子字符串 |
var _message = "Hello World.";
if string_ends_with(_message, ".") || string_ends_with(_message, "?") || string_ends_with(_message, "!")
{
show_debug_message("The message is a valid sentence.");
}
上面的代码首先定义一个字符串,并将其存储在临时变量 _message 中。然后,它调用函数 string_ends_with 来检查字符串是否以以下三个标点符号之一结尾:".", "?" 或 "!"。如果消息以其中任何一个结尾,则会显示调试消息。