子串的摘要从指定位置的文本字符串开始。
string StringSubstr( string string_value, // 字符串 int start_pos, // 初始位置 int length=-1 // 提取的字符串的长度 );
参量
string_value
[in] 字符串提取子串。
start_pos
[in] 子串的初始位置,从0到 StringLen(文本) -1。
length=-1
[in] 提取子串的长度,如果参量值是-1或者没有建立参量,子串会从指定位置提取直到字符串结束。
返回值
复制提取的子串,如果可能的话,否则返回空字符串
示例:
void OnStart() { //--- 获取当前交易品种的名称 string name = Symbol(); //--- 获取交易品种基础货币和报价货币 string base = StringSubstr(name, 0, 3); string quoted = StringSubstr(name, 3, 3); //--- 在日志中显示获得的交易品种货币 PrintFormat("Symbol: %s. Currency base: %s, currency quoted: %s", name, base, quoted); /* 结果 Symbol: EURUSD. Currency base: EUR, currency quoted: USD */ }
另见
StringSplit、StringFind、 StringGetCharacter