去掉空格(100分)

  • 主题发起人 主题发起人 lixiaolong_1
  • 开始时间 开始时间
L

lixiaolong_1

Unregistered / Unconfirmed
GUEST, unregistred user!
去掉字符串中的空格,用那一个函数呢
我的电子邮件地址为
azcq@netease.com
 
可以自己写。我暂时还没看到可以直接去的。
 
stringreplace(str,' ','',[rfreplaceall])
 
trim 去掉空格
lefttrim 去掉左边空格
righttrim 去掉右边空格
 
去掉两边的空格为trim
中间的呢?
 
同意jammi.
 
TrimLeft,TrimRight就是左右了
 
TrimLeft,Trim,TrimRight
 
包去空格:
function deleteBlank(str1:string):string;
var
i,count:integer;
ret:string;
tmp,str:pchar;
begin
str:=pchar(str1);
count:=length(str);
getmem(tmp,256);
i:=0;
while ( i < count ) do
begin
if str>=#128 then
begin
if (( str= #$a1) and (str[i+1] >= #$40) and (str[i+1] <= #$a1)) or
(( str= #$a2) and (((str[i+1] >= #$40) and (str[i+1] <= #$a0)) or((str[i+1] >= #$ab) and (str[i+1] <= #$b0))or ((str[i+1] >= #$e3) and (str[i+1] <= #$e4))or ((str[i+1] >= #$ef) and (str[i+1] <= #$f0)) or ((str[i+1] >= #$fd) and (str[i+1] <= #$ff)) )) or
(( str= #$a3) and (str[i+1] >= #$40) and (str[i+1] <= #$a0)) or
(( str= #$a4) and (((str[i+1] >= #$40) and (str[i+1] <= #$a0))or((str[i+1] >= #$f4) and (str[i+1] <= #$ff)) ) )or
(( str= #$a5) and (((str[i+1] >= #$40) and (str[i+1] <= #$a0))or((str[i+1] >= #$f7) and (str[i+1] <= #$ff)) ) )or
(( str= #$a6) and (((str[i+1] >= #$40) and (str[i+1] <= #$a0))or((str[i+1] >= #$b9) and (str[i+1] <= #$c0)) or ((str[i+1] >= #$d9) and (str[i+1] <= #$df)) or ((str[i+1] >= #$ec) and (str[i+1] <= #$ed))or ((str[i+1] >= #$f6) and (str[i+1] <= #$ff))) )or
(( str= #$a7) and (((str[i+1] >= #$40) and (str[i+1] <= #$a0))or((str[i+1] >= #$c2) and (str[i+1] <= #$d0)) or((str[i+1] >= #$f2) and (str[i+1] <= #$ff)))) or
(( str= #$a8) and (((str[i+1] >= #$96) and (str[i+1] <= #$a0))or((str[i+1] >= #$c1) and (str[i+1] <= #$c4)) or((str[i+1] >= #$ea) and (str[i+1] <= #$ff)))) or
(( str= #$a9) and (((str[i+1] >= #$58) and (str[i+1] <= #$5b))or((str[i+1] >= #$5d) and (str[i+1] <= #$5f)) or((str[i+1] >= #$97) and (str[i+1] <= #$a3))or((str[i+1] >= #$f0) and (str[i+1] <= #$ff)) )) or
(( str= #$aa) and (str[i+1] >= #$a1) and (str[i+1] <= #$ff)) or
(( str= #$ab) and (str[i+1] >= #$a1) and (str[i+1] <= #$ff)) or
(( str= #$ac) and (str[i+1] >= #$a1) and (str[i+1] <= #$ff)) or
(( str= #$ad) and (str[i+1] >= #$a1) and (str[i+1] <= #$ff)) or
(( str= #$ae) and (str[i+1] >= #$a1) and (str[i+1] <= #$ff)) or
(( str= #$af) and (str[i+1] >= #$a1) and (str[i+1] <= #$ff)) or
(( str= #$f8) and (str[i+1] >= #$a1) and (str[i+1] <= #$ff)) or
(( str= #$f9) and (str[i+1] >= #$a1) and (str[i+1] <= #$ff)) or
(( str= #$fa) and (str[i+1] >= #$a1) and (str[i+1] <= #$ff)) or
(( str= #$fb) and (str[i+1] >= #$a1) and (str[i+1] <= #$ff)) or
(( str= #$fc) and (str[i+1] >= #$a1) and (str[i+1] <= #$ff)) or
(( str= #$fd) and (str[i+1] >= #$a1) and (str[i+1] <= #$ff)) or
(( str= #$fe) and (str[i+1] >= #$a1) and (str[i+1] <= #$ff)) or
(( str= #$aa) and (str[i+1] >= #$a1) and (str[i+1] <= #$ff)) or
((( str= #$7f) or (str[i+1] = #$7f)) and (str>#128) ) or
((( str= #$ff) or (str[i+1] = #$ff)) and (str>#128) )
then //a1 a1
begin
tmp[0] := #$0 ;
i :=i+ 2;
// ret:=ret ;
// ret = ret+tmp;
continue;
end
else
begin
tmp[0]:=str;
tmp[1]:=str[i+1];
tmp[2]:=#$0;

ret := ret + tmp ;
i:=i+2;
continue;
end;
end
else
begin
if (str=#$20) then
tmp[0]:=#$0
else
begin
tmp[0]:=str;
tmp[1]:=#$0;
end;
ret := ret + tmp ;
i:=i+1;
continue;
end;
end;
freemem(tmp);
result:=ret;
end;
这里把所有的全角和半角空格都去掉了,保你屡试屡爽
 
用jammi的方法﹐可以去掉所有的空格﹐而用TrimLeft等等﹐如果第一個不是空格﹐那么就
去不掉了。
 
jammis的对
再补充一下
trim 还去掉换行回车符号 #$D#$A
StringReplace 不去掉回车符号 #$D#$A

StringReplace最后的参数若为空,例如:'[]'只替换第一个字符

 
后退
顶部