admin 发表于 2022-9-6 12:20:15

MQL4字符串处理函数


[*]StringConcatenate() – 字符串连接
[*]StringFind() – 字符串搜索
[*]StringGetChar() – 获取字符串中指定字符ASCII值
[*]StringLen() – 获取字符串长度
[*]StringSetChar() – 替换字符串中字符
[*]StringSubstr() – 字符串截取
[*]StringTrimLeft() – 删除字符串前字符
[*]StringTrimRight() – 删除字符串后字符

StringConcatenate() – 字符串连接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);StringFind() – 字符串搜索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!"); StringGetChar() – 获取字符串中指定字符ASCII值int StringGetChar(string text, int pos)返回字符串中指定位置的字符ASCII值。参数:text - 字符串。 pos - 字符串中字符位置,可以从 0 至 StringLen(text)-l。 示例:int char_code=StringGetChar("abcdefgh", 3);// 取出代码 'c' 是 99StringLen() – 获取字符串长度int StringLen(string text)返回一个字符串长度(字符串中字符个数)。参数:text - 字符串。示例:string str="some text";if(StringLen(str)<5) return(0);StringSetChar() – 替换字符串中字符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" StringSubstr() – 字符串截取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"单词 StringTrimLeft() – 删除字符串前字符string StringTrimLeft(string text)本函数删除字符串左侧的回车符、空格和制表符。如果成功,函数将返回删除过的字符串,否则,返回空字符串。参数:text - 字符串。 示例:string str1="Hello world   ";string str2=StringTrimLeft(str);//str2将是 "Hello World   " StringTrimRight() – 删除字符串后字符string StringTrimRight(string text)本函数删除字符串右侧的回车符、空格和制表符。如果成功,函数将返回删除过的字符串,否则,返回空字符串。参数:text - 字符串。 示例:string str1="Hello world   ";string str2=StringTrimLeft(str);//str2将是 "Hello World"

yitang 发表于 2023-9-28 10:02:20

:o

木兮 发表于 2024-3-6 11:01:36

感谢老司机分享,点赞一下

anna 发表于 5 天前

谢谢分享,点赞走起!
页: [1]
查看完整版本: MQL4字符串处理函数