for i:=1 to Length(s-1) do if s[i]=' ' then ShowMessage(s[i+1]);
for i:=1 to Length(s-1) do if (s[i]=' ') AND (s[i+1] <> ' ') then ShowMessage(s[i+1]);
POS来得到每个单词的首位位置 COPY来得到每个单词的第一个字母
分割字符串!!!!!!! 给出实例如下: type TResultArray = array of string;function SplitString(const source, ch: string): TResultArray; var temp: string; i: integer; begin temp := source; i := pos(ch, source); while i <> 0 do begin SetLength(Result, Length(Result) + 1); Result[Length(Result) - 1] := copy(temp, 0, i - 1); delete(temp, 1, i); i := pos(ch, temp); end; SetLength(Result, Length(Result) + 1); Result[Length(Result)-1] := Temp; end; ************** 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; 调用: s:=splitstring('afsdfsdaaa|bbfdsfsdb|ccc','|'); for i:=0 to s.Count-1 do b:=b+s.Strings[i]+#13; showmessage(b); s.free;
POS查找空格的位置,找到每个单词的首位位置。就好办了。
POS查找空格的位置,把每个单词放在TStingList里 用copy 取: var TStrList : TStringList; Str : String; begin TStrList := TStringList.Create; TStrList.Clear; if Str <> '' then begin i := pos(',',str); while i > 0 do begin Tmp := copy(Str,1,i - 1); TStrList.Add(Tmp); Str := copy(Str,i + 1,length(Str)-i); i := pos(',',Str); end; if Str <> '' then begin TStrList.Add(Str); end; end; end;
var slist:TStringList; s: String; i: Integer;slist:=TStringList.Create; slist.DelimitedText := s; slist.Delimiter := ' '; for i=0 to slist.Count-1 do ShowMessage(slist.Strings[i][1]);
Var s, s1, s2, ss: string; i, j: integer; begin //s:='has sent you an e-greeting card'; i:= ansipos(' ',s); if (i<>1) and (s<>'') then ss:= copy(s,1,1); while i<>0 do begin if i<>length(s) then //判断你的字符串的最后一个字符是否为空格 begin s1:=copy(s,i+1,1); ss:=ss + s1; s :=copy(s,i+1,length(s)-i); i :=ansipos(' ',s); end; end; end;
2,现在可以得到了
if s[i]=' ' then
ShowMessage(s[i+1]);
if (s[i]=' ') AND (s[i+1] <> ' ') then
ShowMessage(s[i+1]);
COPY来得到每个单词的第一个字母
给出实例如下:
type
TResultArray = array of string;function SplitString(const source, ch: string): TResultArray;
var
temp: string;
i: integer;
begin
temp := source;
i := pos(ch, source);
while i <> 0 do
begin
SetLength(Result, Length(Result) + 1);
Result[Length(Result) - 1] := copy(temp, 0, i - 1);
delete(temp, 1, i);
i := pos(ch, temp);
end;
SetLength(Result, Length(Result) + 1);
Result[Length(Result)-1] := Temp;
end;
**************
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;
调用:
s:=splitstring('afsdfsdaaa|bbfdsfsdb|ccc','|');
for i:=0 to s.Count-1 do
b:=b+s.Strings[i]+#13;
showmessage(b);
s.free;
用copy 取:
var
TStrList : TStringList;
Str : String;
begin
TStrList := TStringList.Create;
TStrList.Clear;
if Str <> '' then
begin
i := pos(',',str);
while i > 0 do
begin
Tmp := copy(Str,1,i - 1);
TStrList.Add(Tmp);
Str := copy(Str,i + 1,length(Str)-i);
i := pos(',',Str);
end;
if Str <> '' then
begin
TStrList.Add(Str);
end;
end;
end;
slist:TStringList;
s: String;
i: Integer;slist:=TStringList.Create;
slist.DelimitedText := s;
slist.Delimiter := ' ';
for i=0 to slist.Count-1 do
ShowMessage(slist.Strings[i][1]);
s, s1, s2, ss: string;
i, j: integer;
begin
//s:='has sent you an e-greeting card';
i:= ansipos(' ',s);
if (i<>1) and (s<>'') then
ss:= copy(s,1,1);
while i<>0 do
begin
if i<>length(s) then //判断你的字符串的最后一个字符是否为空格
begin
s1:=copy(s,i+1,1);
ss:=ss + s1;
s :=copy(s,i+1,length(s)-i);
i :=ansipos(' ',s);
end;
end;
end;