请问谁有分割字符串的函数? 类似ASP里面的Split... (100分)

O

Orber

Unregistered / Unconfirmed
GUEST, unregistred user!
请问谁有分割字符串的函数? 类似ASP里面的Split函数
我想要的是 只需要提供 关键字 就可以 按 此关键字把字符串分割成数个并且放到一个数组中的函数。

 
function Copy(S
Index, Count: Integer): string;
function Copy(S
Index, Count: Integer): array;
 
Copy函数,自己看帮助。
function Copy(S
Index, Count: Integer): string;
 
//参考如下代码
var
S: string;
begin
S := '1,23,4,5,678,9,0';
with TStringList.Create do try
Text := StringReplace(S, ',', #13#10, [rfReplaceAll]);
ShowMessage(Text);
finally
Free;
end;
end;
 
我想要的是 只需要提供 关键字 就可以 按 此关键字把字符串分割成数个并且放到一个数组中的函数。
 
谢谢zswang,你的代码对我也很多帮助。

 
让人说了
 
用TStringList来分隔,好像只能以','作为分隔符
这段代码是我抄另一位大富翁的,不是我写的,呵呵。
//-------------------------------------------------------
// cb - 分隔字符
// 返回一个TStringList
function SplitString(const source,ch:string):TStringList;
var
temp:string;
i:integer;
begin
result:=tstringlist.Create;
temp:=source;
i:=pos(ch,source);
while i<>0 do
begin
result.Add(copy(temp,0,i-1));
delete(temp,1,i);
i:=pos(ch,temp);
end;
result.Add(temp);
end;
 
谢谢 YoungSun!
 
用pos的话要是字符串中有两个相同的字符,而却我想去后一个怎么办
 
顶部