Delphi中哪个函数可以清除字符串里的空格?

goldenkey 2000-01-18 07:21:00
...全文
880 11 打赏 收藏 转发到动态 举报
写回复
用AI写文章
11 条回复
切换为时间正序
请发表友善的回复…
发表回复
Venne 2000-01-21
  • 打赏
  • 举报
回复
CJ,我们的答案有何区别?
King 2000-01-20
  • 打赏
  • 举报
回复
现成的函数还没听过,为什么不用范式(笑)。
kxy 2000-01-19
  • 打赏
  • 举报
回复
delphi中没有,
LMDReplaceChar(s,' ','');

function LMDReplaceChar(const aValue:String; toReplace, Replace:Char):String;
var
i:Integer;
begin
result:=aValue;
for i:=1 to Length(result) do
if result[i]=toReplace then result[i]:=Replace;
end;
zyb 2000-01-19
  • 打赏
  • 举报
回复
没有什么现成的函数,不过用POS等函数首先查找到空格,然后在DELETE掉不就行啦
supershan 2000-01-19
  • 打赏
  • 举报
回复
too easy!
function trimchar(Str,char:string):String;
begin
while Pos(char,Str)>0 do
Str:=copy(Str,1,pos(char,Str)-1)+copy(Str,pos(char,Str)+1,Length(Str));
Result:=Str;
end;
CJ 2000-01-19
  • 打赏
  • 举报
回复
呵呵,比我的通用,不过,效率未必比我的高呀(搞笑):)
jiangtao 2000-01-19
  • 打赏
  • 举报
回复
来自Rxlib的strutils:
function DelSpace(const S: string): string;
{ DelSpace return a string with all white spaces removed. }

function DelChars(const S: string; Chr: Char): string;
{ DelChars return a string with all Chr characters removed. }



function DelChars(const S: string; Chr: Char): string;
var
I: Integer;
begin
Result := S;
for I := Length(Result) downto 1 do begin
if Result[I] = Chr then Delete(Result, I, 1);
end;
end;


function DelSpace(const S: String): string;
begin
Result := DelChars(S, ' ');
end;
CJ 2000-01-19
  • 打赏
  • 举报
回复
:)
i := pos(s,' ');
while (i <> 0) do
begin
delete(s,i);
i := pos(s,' ');
end;
Venne 2000-01-18
  • 打赏
  • 举报
回复
他的问题大概是问去除字符串里面的空格?:(
渤海海峡 2000-01-18
  • 打赏
  • 举报
回复
trim,trimleft,trimright以及下面一组函数
还有什么对付不了?:)


function LeftStr(OrgStr: string; CharCount: smallint): string;
begin
try
result:=Copy(OrgStr,0,CharCount);
except
result:='';
end;
end;

function RightStr(OrgStr: string; CharCount: smallint): string;
begin
result:=Copy(OrgStr,(Length(OrgStr)-CharCount)+1,Length(OrgStr));
end;

function DeleteChars(OrgStr: string; CharPos, CharCount: smallint): string;
begin
result:=LeftStr(OrgStr,CharPos)+RightStr(OrgStr,Length(OrgStr)-CharPos-CharCount);
end;

function InsertChars(OrgStr, InsChars: string; CharPos : smallint): string;
begin
result:=LeftStr(OrgStr,CharPos)+InsChars+RightStr(OrgStr,Length(OrgStr)-CharPos);
end;

function ReplaceChars(OrgStr, ReplChars: string; CharPos : smallint): string;
begin
result:=LeftStr(OrgStr,CharPos)+ReplChars+RightStr(OrgStr,Length(OrgStr)-CharPos-Length(ReplChars));;
end;

function ReplaceChars2(OrgStr: string; ReplChar: Char; CharPos, CharCount : smallint): string;
var x: smallint;
begin
result:=OrgStr;
for x:=0 to CharCount-1 do
begin
result:=ReplaceChars(result,ReplChar,CharPos+x);
end;
end;

Venne 2000-01-18
  • 打赏
  • 举报
回复
好象没有函数可以这么做,但是我可以有一个算法给你,除空格,或者指定的字符也行:
function trimchar(S,ch:string);
i:=pos(ch,s);
While i<>0 do
begin
delete(S,I,1);
i:=pos(ch,s);
end
其中S为你处理的字符串,ch为需要去除的字符。


5,379

社区成员

发帖
与我相关
我的任务
社区描述
Delphi 开发及应用
社区管理员
  • VCL组件开发及应用社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧