谁能帮我写个过程?(100分)

M

Milpas

Unregistered / Unconfirmed
GUEST, unregistred user!
取出一个字符串中的单词:
procedure ExtractWord(s:string;Index:integer;var Pos,Len:Integer);
给一个字符串s,和单词号Index,得到该单词的位置Pos(字节),和长度(Len)。
 
要做程序员就自己写。
 
procedure ExtractWord(s:string;Index:integer;var Position,Len:Integer);
var
i,n,count,pos1,pos2:Integer;
Start:Boolean;
begin
n:=Length(s);
Start:=false;
count:=1;
Pos1:=0;
Pos2:=0;
for i:=1 to n do
begin
if s in ['a'..'z','A'..'Z'] then
begin
Start:=true;
if (count=Index) and (Pos1=0) then
Pos1:=i;
end
else if Start then
begin
Start:=false;
Inc(count);
if count>Index then
begin
Pos2:=i;
break;
end;
end;
end;
if (Pos1>0) and (Pos2=0) then
Pos2:=n+1;
Len:=Pos2-Pos1;
Position:=Pos1;
end;
procedure TForm1.Button8Click(Sender: TObject);
var
loc,len:Integer;
str:String;
begin
str:='Hello! My friend.Nice to meet you';
ExtractWord(str,4,loc,len);
Caption:=Format('Loc:%d Len=%d',[loc,len]);
end;
 
非常感谢,测试一下先。:)
 
请问怎么给分(初来乍到)?我在接受答案上只看到大鱼儿的名字,找不到creation-zy?
why??????
 
版主,有问题啊!!!!!!!!!!!!!!!!
我为什么不能给分给creation-zy????????????

快说
 
我已经问了,估计是修改贴子造成的。
http://www.delphibbs.com/delphibbs/dispq.asp?lid=539454
 

Similar threads

回复
0
查看
858
不得闲
S
回复
0
查看
953
SUNSTONE的Delphi笔记
S
S
回复
0
查看
775
SUNSTONE的Delphi笔记
S
S
回复
0
查看
1K
SUNSTONE的Delphi笔记
S
顶部