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)
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"單詞
評論前必須登錄!
立即登錄 注冊