参考 › 函数参考 › Functions

Functions.text.ends_with

公共

调用方式

Functions.text.ends_with(str, ending)

将其记录为名为 Functions.text.ends_with 的依赖项(接受自动补全即可完成),然后按该名称调用。

作用

使用 Lua 字符串切片测试字面的字节后缀。空后缀视为匹配;模式字符没有特殊含义,并区分大小写。

参数

名称类型作用
strstring要检查的文本。
endingstring字面后缀,可以为空后缀。

返回值

1boolean文本是否以该确切后缀结尾。

版本

内置辅助函数在每个版本上都会注册。不同的是它们读取的游戏 API;某个 API 缺失时,辅助函数会改用后备方案,或返回 nil 并附上原因。

它不直接读取任何游戏 API。

示例

local name = UnitName("target") or ""
return Functions.text.ends_with(name, "Totem")

源码

Functions/text.lua,第 70 行。在游戏中为只读;“复制”会生成一份可编辑的副本。

Functions.text.ends_with(str, ending)
    return ending == "" or str:sub(-#ending) == ending

返回函数参考