String.starts_with
String.starts_with
功能
判断字符串是否以指定前缀开头。
语法
string.starts_with(prefix)
参数
| 参数 | 类型 | 必填 | 默认值 | 说明 |
|---|---|---|---|---|
| prefix | Any | 否 | 无 | 要匹配的前缀,调用时会先转为字符串。 |
返回值
| 类型 | 说明 |
|---|---|
| Bool | 匹配成功返回 true,否则返回 false。 |
示例
text = 'hello BT' result = text.starts_with('hello') // 输出:true print result
注意事项
- 匹配区分大小写。
- 未传参数时返回 false,避免空参数被当作空字符串误匹配。