StringGetCharacter
StringGetCharacter
从字符串指定位置返回交易品种的值。
ushort StringGetCharacter(
string string_value, // 字符串
int pos // 字符串中交易品种位置
);参量
- string_value
[in] 字符串
- pos
[in] 字符串中交易品种的位置,能够从0到 StringLen(text) -1.
返回值
交易品种代码或错误为0,获得 错误代码 函数调用 GetLastError().
示例:
void OnStart()
{
//--- 删除图表上的所有评论
Comment("");
//--- 声明一个字符串,从中获取交易品种代码值并记住字符串的长度
string message = "The script demonstrates the operation of the StringGetCharacter() function";
int length = StringLen(message);
//--- 声明一个字符串变量,我们将向其中添加从演示字符串中获得的交易品种
string text = "";
//--- 按照演示字符串长度进行循环
for(int i=0; i<length; i++)
{
//--- 等待1/10 秒
Sleep(100);
//--- 从位于演示字符串中循环索引处的字符串获取交易品种
ushort char_code=StringGetCharacter(message, i);
//--- 将交易品种添加到显示的字符串中,并将结果字符串显示为图表评论
text+=ShortToString(char_code);
Comment(text);
}
//--- 等待两秒钟,然后从图表中删除评论
Sleep(2000);
Comment("");
/*
Result: the demo string appears on the screen character by character
The script demonstrates the operation of the StringGetCharacter() function
*/
}另见
StringSetCharacter、StringBufferLen、 StringLen、StringFill、 StringInit、StringToCharArray、 StringToShortArray