
- StringConcatenate() – 字符串连接
- StringFind() – 字符串搜索
- StringGetChar() – 获取字符串中指定字符ASCII值
- StringLen() – 获取字符串长度
- StringSetChar() – 替换字符串中字符
- StringSubstr() – 字符串截取
- StringTrimLeft() – 删除字符串前字符
- StringTrimRight() – 删除字符串后字符
string StringConcatenate(...)
本函数生成字符串形式的报告而且返回。参数可以为任意类型,总数不胜过64个。
依照Print(), Alert() 和 Comment() 函数的同样规则,把参数转换成字符串,其返回值就是把函数参数转换成字符串再连接起来的结果。
StringConcatenate() 函数要比运用加号运算符(+)连接字符串运行更快、更节省内存。
参数:
... - 用逗号分隔所有字符串,最多64个参数。
示例:
string text; text=StringConcatenate("Account free margin is ", AccountFreeMargin(), "Current time is ", TimeToStr(TimeCurrent()));// 文本="Account free margin is " + AccountFreeMargin() + "Current time is " + TimeToStr(TimeCurrent()) Print(text);
int StringFind(string text, string matched_text, void start)
搜索子字符串。函数返回子字符串在搜索字符串中开始位置,假使未寻到,返回-1 。
参数:
text - 被搜索的字符串。 matched_text - 需要搜索的字符串。 start - 搜索开始索引位置。
示例:
string text="迅速的棕色小狗逾越过懒惰的狐狸"; int index=StringFind(text, "小狗逾越", 0);if(index!=16) Print("oops!");
int StringGetChar(string text, int pos)
返回字符串中指定位置的字符ASCII值。
参数:
text - 字符串。 pos - 字符串中字符位置,可以从 0 至 StringLen(text)-l。
示例:
int char_code=StringGetChar("abcdefgh", 3);// 取出代码 'c' 是 99
int StringLen(string text)
返回一个字符串长度(字符串中字符个数)。
参数:
text - 字符串。
示例:
string str="some text"; if(StringLen(str)<5) return(0);
string StringSetChar(string text, int pos, int value)
返回在指定位置被替换过字符的字符串。
参数:
text - 字符串。pos - 字符串中字符位置,可以从0至 StringLen(text)-1。 value - 新字符的 ASCII 代码。
示例:
string str="abcdefgh"; string str1=StringSetChar(str, 3, 'D');// str1 is "abcDefgh"
string StringSubstr(string text, int start, void length)
从字符串给出的位置起截取子字符串。
假使或许,此函数返回提取的子字符串,否则,返回一个空字符串。
参数:
text - 字符串。start - 子字符串开始的位置,可以从0至 StringLen(text)-1。 length - 字符串截取长度。大于等于0;假使参数没有指定,从给定的位置起截取到串尾。
示例:
string text="The quick brown dog jumps over the lazy fox"; string substr=StringSubstr(text, 4, 5);// 截取的字串符是"quick"单词
string StringTrimLeft(string text)
本函数删除字符串左侧的回车符、空格和制表符。假使成功,函数将返回删除过的字符串,否则,返回空字符串。
参数:
text - 字符串。
示例:
string str1=" Hello world "; string str2=StringTrimLeft(str);//str2会是 "Hello World "
string StringTrimRight(string text)
本函数删除字符串右侧的回车符、空格和制表符。假使成功,函数将返回删除过的字符串,否则,返回空字符串。
参数:
text - 字符串。
示例:
string str1=" Hello world "; string str2=StringTrimLeft(str);//str2会是 " Hello World"