📅 财经日历 📊 实时波动 📈 大盘云图 📶 行情走势 🆚 投机情绪 🚀 今日热点

    MT5 字符串函数及示例

    xImbsx LV4
    2019-04-28 · 4258 阅读
    本帖最后由 xImbsx 于 2019-4-28 08:14 编辑

    字符串函数[String Functions]

    string StringConcatenate( ... ) 字符串连接
    :: 输入参数
    ... - 任意值,用逗号分割
    示例:
    stringtext;
    text=StringConcatenate("Account free margin is ",AccountFreeMargin(), "Current time is ", TimeToStr(CurTime()));
    // slow text="Account free margin is " + AccountFreeMargin() +"Current time is " + TimeToStr(CurTime())
    Print(text);


    int StringFind( stringtext, string matched_text, int start=0)
    在字符串中寻找符合条件的字符串返回索引位置
    :: 输入参数
    text - 被搜索的字符串
    matched_text - 需要搜索的字符串
    start - 搜索开始索引位置
    示例:
    stringtext="The quick brown dog jumps over the lazy fox";
    int index=StringFind(text, "dog jumps", 0);
    if(index!=16)
    Print("oops!");


    int StringGetChar(string text, int pos)
    取字符串中的某一个字符
    :: 输入参数
    text - 字符串
    pos - 取字符的位置
    示例:
    intchar_code=StringGetChar("abcdefgh", 3);
    // char code 'c' is 99


    int StringLen( stringtext)
    返回字符串长度
    :: 输入参数
    text - 字符串
    示例:
    stringstr="some text";
    if(StringLen(str)<5) return(0);


    string StringSetChar(string text, int pos, int value)
    在字符串中设置一个字符
    :: 输入参数
    text - 字符串
    pos - 设置字符的位置
    value - 新的字符
    示例:
    stringstr="abcdefgh";
    string str1=StringSetChar(str, 3, 'D');
    // str1 is "abcDefgh"


    string StringSubstr(string text, int start, int count=EMPTY)
    从字符串中截取一段字符串
    :: 输入参数
    text - 字符串
    start - 开始索引位置
    count - 截取字符数
    示例:
    stringtext="The quick brown dog jumps over the lazy fox";
    string substr=StringSubstr(text, 4, 5);
    // subtracted string is "quick" word


    string StringTrimLeft(string text)
    字符串左侧去空格
    :: 输入参数
    text - 字符串
    示例:
    stringstr1=" Hello world ";
    string str2=StringTrimLeft(str);
    // after trimming the str2 variable will be "Hello World "


    string StringTrimRight(string text)
    字符串右侧去空格
    :: 输入参数
    text - 字符串
    示例:
    stringstr1=" Hello world ";
    string str2=StringTrimRight(str);
    // after trimming the str2 variable will be " Hello World"




    ""
    还没有人打赏,支持一下
    回复

    举报

     

    回答|共 9 个

    黄昏 LV3

    发表于 2020-7-27 18:31:01 | 显示全部楼层

    学习了,不错

    改变 LV3

    发表于 2020-8-1 20:46:44 | 显示全部楼层

    谢谢楼主分享

    唐嬿丰 LV7

    发表于 2020-8-9 15:10:00 | 显示全部楼层

    帮你顶下哈!!

    wufrd LV6

    发表于 2020-8-10 14:43:32 | 显示全部楼层

    谢谢楼主分享

    btclyb85 LV3

    发表于 2020-8-15 10:47:23 | 显示全部楼层

    学习了,不错

    刚和你似的 LV3

    发表于 2020-11-23 10:21:32 | 显示全部楼层

    谢谢

    qytz LV1

    发表于 2025-5-13 13:20:40 | 显示全部楼层

    支持下

    点点 LV1

    发表于 2025-10-3 17:26:29 | 显示全部楼层

    谢谢

    去买买 LV1

    发表于 2025-11-15 12:45:34 | 显示全部楼层

    顶下
    您需要登录后才可以回帖 登录 | 注册

    提醒: 禁止引战、谩骂、灌水内容

    微信二维码

    有问题联系客服