首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > .NET > .NET >

如何过滤字符串

2012-08-11 
怎么过滤字符串?比如一个字符串是“123你好456Hello”要求过滤后S1:‘123456’S2:‘你好’S3:Hello也就是把

怎么过滤字符串?
比如一个字符串是“123你好456Hello”
要求过滤后
S1:=‘123456’
S2:=‘你好’
S3:='Hello'
也就是把数字、英文、汉字都单独提出来。
请问应该用什么函数?谢谢

[解决办法]

Delphi(Pascal) code
procedure TForm1.FormCreate(Sender: TObject);var  I, One: Integer;  S: WideString;  S1,S2,S3: string;begin  S := '123你好456Hello';  S1 := ''; S2 := ''; S3 := '';  for I := 1 to Length(S) do  begin    One := Integer(S[I]);    if (One >= Ord('0')) and (One <= Ord('9')) then      S1 := S1 + S[I]    else if ((One >= Ord('a')) and (One <= Ord('z'))) or ((One >= Ord('A')) and (One <= Ord('Z'))) then      S3 := S3 + S[I]    else      S2 := S2 + S[I]  end;  ShowMessage(S1);  ShowMessage(S2);  ShowMessage(S3);end;
[解决办法]
Delphi(Pascal) code
var  i:integer;  s1,s2,s3:string;  s:widestring;begin  s:='123你好456Hello';  for i:=1 to length(s) do  begin    if Ord(s[i]) in [48..57] then       s1:=s1+s[i]    else if Ord(s[i]) in [65..90,97..122] then       s2:=s2+s[i]    else       s3:=s3+s[i];  end;  showmessage(s1+s2+s3);end; 

热点排行