StringSplit

在指定字符串通过指定分隔符得到子字符串,返回所得子字符串的数量

int  StringSplit(
   const string   string_value,       // 字符串搜索
   const ushort   separator,          // 被搜索子字符串使用的分隔符
   string         & result[]          // 通过引用传递数组得到寻找的子字符串
   );

参数

string_value

[in]  您需要获得子字符串的字符串。字符串不能改变。

pos

[in]  分隔符的字符代码。要获得代码,您可以使用 StringGetCharacter() 函数。

result[]

[out]  获得的子字符串所在的字符串数组。

返回值

result[]数组中的子字符串数量。如果在过去的字符串没有找到分隔符,那么将只有源字符串位于数组中。

如果string_value 为空或NULL,函数将返回零。如果发生错误,则函数返回-1.若要获得错误代码,请调用GetLastError()函数。

例如:

string to_split="_life_is_good_"// 字符串分成子字符串
   string sep="_";                // 分隔符为字符
   ushort u_sep;                  // 分隔符字符代码
   string result[];               // 获得字符串数组
   //--- 获得分隔符代码
   u_sep=StringGetCharacter(sep,0);
   //--- 字符串分为子字符串
   int k=StringSplit(to_split,u_sep,result);
   //--- 显示注释 
   PrintFormat("Strings obtained: %d. Used separator '%s' with the code %d",k,sep,u_sep);
   //--- 现在输出所有获得的字符串
   if(k>0)
     {
      for(int i=0;i<k;i++)
        {
         PrintFormat("result[%d]=\"%s\"",i,result[i]);
        }
     }

另见

StringReplace(), StringSubstr(), StringConcatenate()