试一下这个
procedure TForm1.Button1Click(Sender: TObject);
var
i,j :integer ;
s,temp:string ;
myArray : Array[0..10]of string ;
begin
s := '清华大学96工业分析2班8排6座';
j:= 0 ;
temp:= '';
for i:= 1 to length(s) do
begin
if ( s[i] in ['0'..'9'] ) and not ( s[i-1] in ['0'..'9'] )then
begin
myArray[j] := temp ;
j:= j+1 ;
temp:= s[i] ;
end else
temp:= temp+s[i];
end ;
myArray[j] := temp ;
for j := 0 to 5 doshowmessage(myArray[j]);
end ;
procedure TForm1.Button1Click(Sender: TObject);
var
i,j :integer ;
s,temp:string ;
myArray : Array[0..10]of string ;
begin
s := '清华大学96工业分析2班8排6座';
j:= 0 ;
temp:= '';
for i:= 1 to length(s) do
begin
if ( s[i] in ['0'..'9'] ) and not ( s[i-1] in ['0'..'9'] )then
begin
myArray[j] := temp ;
j:= j+1 ;
temp:= s[i] ;
end else
temp:= temp+s[i];
end ;
myArray[j] := temp ;
for j := 0 to 5 doshowmessage(myArray[j]);
end ;
我并不是指按数字剖析开来
我只希望按一个特定的字符如'|'剖析开来
也就是说
我们|你|她们
希望的结果是
myArray[0]='我们';
myArray[1]='你';
myArray[2]='她们';
试一下这个
procedure TForm1.Button1Click(Sender: TObject);
var
i,j :integer ;
s,temp:string ;
myArray : Array[0..10]of string ;
begin
s := '清华大学¦96工业分析¦2班¦8排¦6座';
j:= 0 ;
temp:= '';
for i:= 1 to length(s) do
begin
if ( s[i] = '¦' ) and not ( s[i-1] = '¦' )then
begin
myArray[j] := temp ;
j:= j+1 ;
temp:= s[i] ;
end else
temp:= temp+s[i];
end ;
myArray[j] := temp ;
for j := 0 to 5 doshowmessage(myArray[j]);
end ;
procedure TForm1.Button1Click(Sender: TObject);
var
i,j :integer ;
s,temp:string ;
myArray : Array[0..10]of string ;
begin
s := '清华大学|96工业分析|2班|8排|6座';j:= 0 ;
temp:= '';
for i:= 1 to length(s) do
begin
if ( s[i] ='|' ) and not ( s[i-1] ='|' )then
begin
myArray[j] := temp ;
j:= j+1 ;
temp:='';
end else
temp:= temp+s[i];
end ;
myArray[j] := temp ;
for j := 0 to 5 doshowmessage(myArray[j]);
end ;
TResultArray = array of string;function SplitString(const source, ch: string): TResultArray;
var
temp: string;
i: integer;
begin
temp := source;
i := pos(ch, source);
while i <> 0 do
begin
SetLength(Result, Length(Result) + 1);
Result[Length(Result) - 1] := copy(temp, 0, i - 1);
delete(temp, 1, i);
i := pos(ch, temp);
end;
SetLength(Result, Length(Result) + 1);
Result[Length(Result)-1] := Temp;
end;
var
I, L: Integer;
Left: AnsiString;
begin
Assert(List <> nil);
List.Clear;
L := Length(Sep);
I := Pos(Sep, S);
while (I > 0) do
begin
Left := StrLeft(S, I - 1);
List.Add(Left);
Delete(S, 1, I + L - 1);
I := Pos(Sep, S);
end;
if S <> '' then
List.Add(S);
end;
比较老的代码改一下!
我需要最简单的
不过看来是没有希望一个函数就能搞定的哪
唉,用过PHP的explode返回来在delphi里实现不了
真是不爽呀