string_ends_with

此函数用于检查字符串是否以给定子字符串结尾。如果以给定子字符串结尾,则返回 true,否则返回 false

 

语法:

string_ends_with(str, substr);

参数类型描述
strString要检查给定子字符串在末尾是否出现的字符串
substrString字符串结尾的子字符串

 

返回:

Boolean

 

例子:

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 来检查字符串是否以以下三个标点符号之一结尾:".", "?""!"。如果消息以其中任何一个结尾,则会显示调试消息。