分解字符串,同PHP的 explode

var
  type userarray
= array  of  string ;
implementation

function   split (s : string ; dot :  char) : userarray;
var
  str
: userarray;
  i
, j : integer ;
begin
  i
:= 1 ;
  j
:= 0 ;
  SetLength(str
,   255 );
  
while   Pos (dot ,  s)  >   0   do
  begin
    str[j]
:= copy (s , i , pos (dot , s) - i);
    i
:= pos (dot , s) + 1 ;
    s[i
- 1 :=   chr ( ord (dot) + 1 );
    j
:= j + 1 ;
  
end ;
  str[j]
:= copy (s , i , strlen (pchar(s)) - i + 1 );
  result
:= str;
end ; // split

procedure TForm3
. FormShow(Sender :  TObject);
var
   Temp
:  userarray;
begin
    Temp 
:=   split ( ' 1,2,3,4 ' , ' , ' );
end ;
 

你可能感兴趣的:(Delphi,php,integer,string,function)