- 人气:
- 放大
- 缩小
- 二维码
- 赞赏
delphi 删除字符串重复的符号只保留一个
aaaa 0.1
bbbbb 1.23
asdfadf 1254
=====================
想把上面的字符串变成之间只有一个空格:
aaaa 0.1
bbbbb 1.23
asdfadf 1254
//删除字符串重复的符号
function StrPosCount(subs:string;source:string):integer;
var
Str : string;
begin
Result := 0;
str := source;
while Pos(Subs,Str)<>0 do
begin
Delete(Str,Pos(Subs,Str),Length(Subs));
Inc(Result);
end;
end;
function StrPosCount2(subs:string;source:string):string;
var
Str : string;
begin
Result :='';
str := source;
while Pos(Subs,Str)<>0 do
begin
if StrPosCount(Subs,Str)=1 then break; //关键的地方在这里
Delete(Str,Pos(Subs,Str),Length(Subs));
Result:=Str;
end;
end;
调用方法:StrPosCount2('=',str1);