EATC

 找回密码
 立即注册
查看: 547|回复: 2

MQL4字符串处理函数

[复制链接]

192

主题

1118

帖子

1201

积分

管理员

Rank: 9Rank: 9Rank: 9

积分
1201
发表于 2022-9-6 12:20:15 | 显示全部楼层 |阅读模式
  • 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' 是 99  StringLen() – 获取字符串长度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"
回复

使用道具 举报

2275

主题

3779

帖子

2万

积分

交易元老

Rank: 8Rank: 8

积分
26669
发表于 2023-9-28 10:02:20 | 显示全部楼层
回复

使用道具 举报

460

主题

1464

帖子

4965

积分

交易元老

Rank: 8Rank: 8

积分
4965
发表于 2024-3-6 11:01:36 | 显示全部楼层
感谢老司机分享,点赞一下
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

收藏本站|法律声明|Archiver|小黑屋|support@ea198.com|EATC ( 桂ICP备2022005787号 )

风险提示与免责声明:擅自从事外汇保证金交易的双方不受法律保护!社区内展示内容,均为网友自发分享,不构成投资建议,社区无法全面监控由第三方上传至社区的资源,因此不保证资源的合法性、安全性、完整性、真实性或品质等。您下载时,同意自行判断并承担所有风险。社区内的资源,仅限用于学习和研究目的,不得将用于商业或者非法用途,否则,一切后果请用户自负。社区信息来自网络,版权争议与社区无关,您下载后须在24个小时之内进行删除。如果您喜欢该内容,请支持正版。如有侵权请邮件与我们联系处理。