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);

相关阅读 >>

在xp/2k 下实现 win+ctrl+del 等键的屏蔽的方法

Delphi内存映射 与 映射数据获取

Delphi 生成可以控制最大32位随机英文数字字符串

Delphi fastreport 直接列印

Delphi 使用 inputbox、inputquery 的启发

Delphi 取得和设置当前系统的短日期格式

Delphi xe 获取硬盘id序列号

Delphi 中流的使用通过内存流读取文件

Delphi瞬间消除无用托盘图标(刷新托盘)

Delphi实现文件下载urldownloadtofile

更多相关阅读请进入《Delphi》频道 >>



打赏

取消

感谢您的支持,我会继续努力的!

扫码支持
扫码打赏,您说多少就多少

打开支付宝扫一扫,即可进行扫码打赏哦

分享从这里开始,精彩与您同在

评论

管理员已关闭评论功能...