下载MetaTrader 5
要添加评论,请登录注册
对MQL5.community的伙伴计划感兴趣吗?放入网站链接并获利
龙飞
86
龙飞 2007.02.22 17:44 
比如
string strInfo="aae|aer3|dzse|faw323";
string strResult[] ;
strResult = strInfo.split('|');

结果为:
strResult[0]==aae;
strResult[1]==aer3;
strResult[2]==dzse;
strResult[3]==faw323;

大哥们帮帮忙,如果有其他的好的函数可以做,帮帖出,谢谢!
Rashid Umarov
管理员
6605
Rashid Umarov 2007.02.23 15:12  
See this example:

//+------------------------------------------------------------------+
//|                                                        Split.mq4 |
//|                      Copyright © 2007, MetaQuotes Software Corp. |
//|                                        http://www.metaquotes.net/ru/ |
//+------------------------------------------------------------------+
#property copyright "Copyright © 2007, MetaQuotes Software Corp."
#property link      "http://www.metaquotes.net/ru/"
 
 
//+------------------------------------------------------------------+
//|  fill array of strings                                           |
//+------------------------------------------------------------------+
void SplitString(string &ArrayRes[],string InputString,string splitter)
  {
   string temp,tempArray[100];
   int pos,splitLength=StringLen(splitter),InputStrLength=StringLen(InputString),counter;
 
   pos=StringFind(InputString,splitter);
   if (pos!=-1)
      {
      if (pos==0) InputString=StringSubstr(InputString,splitLength,InputStrLength-splitLength);
      while (StringFind(InputString,splitter)!=-1)
         {
         pos=StringFind(InputString,splitter);
         InputStrLength=StringLen(InputString);
         tempArray[counter]=StringSubstr(InputString,0,pos);
         InputString=StringSubstr(InputString,pos+splitLength,InputStrLength-splitLength-pos);
         counter++;
         }
      if (StringLen(InputString)!=0)
         {
         tempArray[counter]=InputString;
         counter++;
         }  
      }
   ArrayResize(ArrayRes,counter);
   for (int i=0;i<counter;i++) 
      {
      ArrayRes[i]=tempArray[i];
      Print("i=",i,"   string=",ArrayRes[i]);
      }
   return;  
  }
 
//+------------------------------------------------------------------+
//| script program start function                                    |
//+------------------------------------------------------------------+
int start()
  {
//----
   string strInfo="aae|aer3|dzse|faw323";
   string strResult[] ;
  
   SplitString(strResult,strInfo,"|");
  
   int N=ArraySize(strResult);
   if (N>0)
      {
      for (int i=0;i<N;i++) Print("strResult[",i,"]=",strResult[i]);
      }
//----
   return(0);
  }
//+------------------------------------------------------------------+
Rashid Umarov
管理员
6605
Rashid Umarov 2007.02.23 21:36  
I have forgotten to inform, that it is a script.
龙飞
86
龙飞 2007.03.09 17:24  
牛,可惜我自己做了个其他的方法实现了
! 仍然严重感谢!
/
要添加评论,请登录注册