跳转至

string 字符串处理库

桃奈月月子提出,可以对字符串进行简单的子串索引查找,匹配子串,以及分割字符串等操作
include "string";语句导入

contains 检查子串是否存在

  • 参数1 STRING 被检查字符串
  • 参数2 STRING 用于检查的子串
1
2
3
4
5
6
include "system";
include "string";

value local str:"串" = "Hello! World!";

system.print(string.contains(str,"World!"));
true

indexof 检查子串第一次出现的位置

  • 参数1 STRING 被检查的字符串
  • 参数2 STRING 检查的子串
1
2
3
4
5
6
include "system";
include "string";

value local str:"串" = "Hello! World!";

system.print(string.indexof(str,"World!"));
7
你知道的太多了

作者在实际测试这段代码的时候发现虚拟机发生形参不匹配错误,检查的时候发现InvokeParser编译出的字节码不含有任何参数,最开始以为是编译器的新BUG,最后一查才发现system.print(string.indexof(str,"World!"));写成了system.print(string.indexof(str,"World!");少了末尾的括号,所以出BUG了

split 分割字符串

  • 参数1 STRING 被分割的字符串
  • 参数2 STRING 分割的子串
  • 返回值 ARRAY 分割后的数组
1
2
3
4
5
6
include "system";
include "string";

value local str:"串" = "Hello! World!";

system.print(string.split(str,"World"));
[[STRING]:Hello! [STRING]:!]

splite函数会按照参数2指定的字符串分割成数组并返回