5.16 String functions字符串函数
关于字符串类型数据的一组函数。
5.16.1 StringConcatenate字符串连接
string StringConcatenate(…)
数据的字符串形式通过并且返回。参量可以为任意类型。通过参量的总数不得超过64个字符。
作为应用到Print( ) ,Alert()和Comment( )函数的参量,按照同样规则传送。从函数参量返回获取的字符串作为连接结果。
当字符串连续使用(+)添加时,StringConcatenate)运行较快,并且会存储。
【参量】
···—所有价格值由逗号分开。它可以有64个参量。
【示例】
string text;
text=StringConcatenate”Account free margin is”,AccountFreeMargin),”Current timeis”,TimeToStr('fimeCurrent)));
//文本=" Account free margin is "+AccountFreeMargin ( ) + " Current time is "+TimeToStr( TimeCurrent())
Print ( text );
5.16.2 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!”);
5.16.3 StringGetChar字符串指定位置代码
int StringGetChar( string text,int pos)
从字符串指定位置返回代码。
【参量】
Text一字符串。
取字符的位置。可以自0至StringLen( text) - 1int char code
//取出代码
=StringGetChar(”abcdefgh" ,3);
'c’是99
5.16.4 StringLen字符串长度
StringLen ( string text )
在字符串中返回代码数。Returns character count in a string
【参量】
算字符串长度。
string str=”some text"
if( StringLen( str)<5)return ( 0);
5.16.5 StringSetChar替换字符
string StringSetChar( string text,int pos,int value)在指定位置返回带有改变代码的字符串复本。
【参量】
TextPos一改变的字符串代码。
字符串种代码的位置。可以自。至StringLen (text )
Value—新取得的ASCII代码。
【示例】
string str=”stringh;
aiu:defgh";=StringSetChar( str,3.'u);
//ctrl is”ahcDefgh"
5.16.6 StringSubstr提取子字符串
string StringSubstr( string text,int start,void length )
从给出位置的文本字符串的开端提取字符串。
如果可能,此函数将返回提取字符串的副本,否则返回空字符串。
【参量】
Text—将被提取的字符串。
Start—字符串开始索引。可以是自0至StringLen ( text)一toLength—字符串提取的宽度。如果参量值大于或等于零,或者参量没有指定,字符串将被提取〕
【示例】
string text=”快速的棕色小狗跨越过懒惰的狐狸”;
string substr=StringSuhstr( text,4,5):
//减去字符串是”快速”单词
5.16.7 StringTrimLeft剪除字符串左边空格
string StringTrimLeft( string text)
剪去字符串左边的空格。
【参量】
Text—左侧剪切的字符串。
【示例】
string slrl=”Hello world”;
string str2=StringTri ml,eft (str );
//在剪切str2将是”Hello World”
5.16.8 StringTrimRight剪除字符串右边空格
string StringTrimRight( string text)
剪去字符串右边空格
【参量】
Text—右侧剪切的字符串。
【示例】
string strl=”Hello world”;
string str 2=StringTrimRight( str);
//在剪切str 2之后将是’' Hello World"