一个关于字符串读取和处理的问题!急救啊!(50分)

Z

zk75210

Unregistered / Unconfirmed
GUEST, unregistred user!
假如我从edit1.text中得到一串字符串为:“http://www.163.com^@^Pocket Name^@^5200^@^013 ”

我想把其中的http://www.163.com和pccket name和5200和013这几个字符的分别赋值到str1、str2

、str3、str4几个字符变量里面去!也就是这样:

str1:='http://www.163.com'
str2:='pocket name'
str3:='5200'
str4:='013'

可是我如何从那一串字符中把各段文字提取出来呢!(我只知道字符串中各段之间用^@^符号隔开)
 

Procedure SplitTextIntoWords(Const S: String; var words: TStringlist);
Var
startpos, endpos: Integer;
Begin
Assert(Assigned( words ));
words.clear;
startpos := 1;
While startpos <= Length(S) Do Begin
// skip non-letters
While (startpos <= Length(S)) and not IsCharAlpha(S[startpos]) Do
Inc(startpos);
If startpos <= Length(S) Then Begin
// find next non-letter
endpos := startpos + 1;
While (endpos <= Length(S)) and IsCharAlpha(S[endpos]) Do
Inc(endpos);
words.add( Copy( S, startpos, endpos-startpos));
startpos := endpos+1;
End; { If }
End; { While }
End;
 
给些详细中文说明好吗???谢谢!!最好能用上我给出的哪个字符串做个例子!

拜托了!谢谢!
 
我想问下那个字符串是URL吗???好像不是吧,是URL的话就好办,用WININET的一个函数就搞定。
 
可以这样:
1、先用pos()函数找到第一个 ^@^的位置,再用leftstr()函数截取第一段字符串,
2、将剩下的字符赋值给新的变量,重复第一步即可将多段字符截出。
以上的函数 在 strutils中,在uses中添加
 
不是URL!
 
你可以看看delphi的字符串处理函数比如copy,delete,insert,等等还有好多,应该可以实现
你要的功能,但是程序最好自己写,增加经验值吗
 
顶部