StringConcatenate() – 字符串连接
StringFind() – 字符串搜索
StringGetChar() – 获取字符串中指定字符ASCII值
StringLen() – 获取字符串长度
StringSetChar() – 替换字符串中字符
StringSubstr() – 字符串截取
StringTrimLeft() – 删除字符串前字符
StringTrimRight() – 删除字符串后字符
StringConcatenate() – 字符串连接
string StringConcatenate(...)本函数生成字符串形式的数据并返回。参数可以是任意类型,总数不超过64个。按照Print()、Alert()和Comment()函数的转换规则,将参数转为字符串后再进行连接。相比使用加号运算符(+),使用StringConcatenate()在性能上更优,运行更快且内存消耗更少。例如,在pepperstone激石等平台编写EA时,经常需要将账户信息与时间动态拼接,该函数就能高效完成这一任务。
参数:...用逗号分隔所有参数,最多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)-1。
示例:
int char_code=StringGetChar("abcdefgh", 3); // 取出字符'd'的ASCII码是100
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变成 "abcDefgh"
StringSubstr() – 字符串截取
string StringSubstr(string text, int start, void length)从指定位置开始截取子字符串。若成功则返回提取的子串,否则返回空字符串。
参数:text为源字符串;start为起始位置(0至StringLen(text)-1);length为截取长度(≥0,若不指定则从start截取到串尾)。
示例:
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(str1); // str2变为 "Hello world "
StringTrimRight() – 删除字符串后字符
string StringTrimRight(string text)删除字符串右侧的回车符、空格和制表符。成功则返回处理后的字符串,否则返回空字符串。
参数:text为字符串。
示例:
string str1=" Hello world ";
string str2=StringTrimRight(str1); // str2变为 " Hello world"
资深外汇分析师
由多名资深外汇分析师组成的专业团队,拥有平均15年以上的市场分析经验,擅长技术分析和基本面分析相结合的交易策略。