这样
如果单词串是WordStr
procedure ExtractWord(s:string;Index:integer;var Pos,Len:Integer);
begin
pos:=ansipos(WordStr[index].text,s);
len:=length(WordStr);
end;
如果单词串是WordStr
procedure ExtractWord(s:string;Index:integer;var Pos,Len:Integer);
begin
pos:=ansipos(WordStr[index].text,s);
len:=length(WordStr);
end;
procedure ExtractWord(s:string;Index:integer;var Pos,Len:Integer);
begin
pos:=ansipos(WordStr[index].text,s);//子串位置
len:=length(s);//子串长度
end;
例如:s:='I have a good time.'
index:=4;
然后求出‘good'的位置和长度。
procedure ExtractWord(s:string;Index:integer;var Pos,Len:Integer);
var
i,j:integer;
flag:boolean;
begin
i:=0;
flag:=true;
if s[0]<>' ' then
begin
Index:=Index-1;
flag:=false;
end;
i:=i+1;
while i<=Length(s) and Index>0 do
begin
if s[i]<>' ' and flag=true then
begin
Index:=Index-1;
flag:=false;
end;
i:=i+1
end;
if Index:=0 then Pos:=i
else 出错;
while s[i]<>' ' do
i:=i+1;
len:=i-Pos;
end;
比如“I am single of single”,如果查第二个single就会出错的,呵呵。
当然俺的解法可能错误更多。
新手上路,请多指教。
In traditional Pascal programming, all source code, including the main program, is stored in .PAS files. Delphi uses a project (.DPR) file to store the 搈ain?program, while most other source code resides in unit (.PAS) files. Each application梠r project梒onsists of a single project file and one or more unit files. (Strictly speaking, you needn抰 explicitly use any units in a project, but all programs automatically use the System unit.) To build a project, the compiler needs either a source file or a previously compiled DCU for each unit.其实也不仅仅是空格啦。3Q