function QTrim(const S: String): String; var I, L: Integer; begin L := Length(S); I := 1; while (I <= L) and (S[I] <=' ') do Inc(I); if I > L then Result := '' else begin while S[L] <= ' ' do Dec(L); Result := Copy(S, I, L - I + 1); end; end;帮着改改呗。初学DEPHI 谢谢大家了
function QTrim(const S: String): String; var I, L: Integer; begin L := Length(S); I := 1; while (I <= L) and (S[I] <=' ') do Inc(I); if I > L then Result := '' else begin while S[L] <= ' ' do Dec(L); Result := Copy(S, I, L - I + 1); end; end;帮着改改呗。初学DEPHI 谢谢大家了
var i, n: Integer; s: string; begin s := ' 你好 世界 '; n := Length(s); i := 1; // 去头 while (i < n) and (s[i] = #161) do begin if s[i + 1] = #161 then begin Delete(s, i, 2); Dec(n, 2); end else Inc(i); end; i := Length(s); // 去尾 while (i > 1) and (s[i] = #161) do begin if s[i - 1] = #161 then begin Delete(s, i - 1, 2); Dec(i); end; Dec(i); end; ShowMessage(s); end;
只去前后的空格 快来帮忙啊 文字中间的空格不去。---------------------- 那你调用这个过程就可以了:uses StrUtils;function QTrim(const S: String): String; var tmp:WideString; begin tmp:=s; while AnsiStartsText(' ',tmp) do tmp:=copy(tmp,2,length(tmp)); while AnsiEndsText(' ',tmp) do tmp:=copy(tmp,1,length(tmp)-1); QTrim:=tmp; end;
var s:string; begin s:='你好 中 国!'; s:=StringReplace(s,' ','',[rfReplaceAll]); showmessage( s ); end;
s: string;
i: Integer;
begin
s := ' 你好!';
i := Pos(#161, s);
if (i <> 0) and (s[i + 1] = #161) then
Delete(s, i, 2);
ShowMessage(s);
end;
var s:widestring;
begin
s:=' 你 好 ,我 是中 国 人!';
s:=AnsiReplaceStr(s,' ','');
showmessage(s)
end;
var
I, L: Integer;
begin
L := Length(S);
I := 1; while (I <= L) and (S[I] <=' ') do Inc(I);
if I > L then Result := '' else
begin
while S[L] <= ' ' do Dec(L);
Result := Copy(S, I, L - I + 1);
end;
end;帮着改改呗。初学DEPHI 谢谢大家了
var
I, L: Integer;
begin
L := Length(S);
I := 1; while (I <= L) and (S[I] <=' ') do Inc(I);
if I > L then Result := '' else
begin
while S[L] <= ' ' do Dec(L);
Result := Copy(S, I, L - I + 1);
end;
end;帮着改改呗。初学DEPHI 谢谢大家了
var
i, n: Integer;
s: string;
begin
s := ' 你好 世界 ';
n := Length(s);
i := 1;
// 去头
while (i < n) and (s[i] = #161) do
begin
if s[i + 1] = #161 then
begin
Delete(s, i, 2);
Dec(n, 2);
end
else
Inc(i);
end;
i := Length(s);
// 去尾
while (i > 1) and (s[i] = #161) do
begin
if s[i - 1] = #161 then
begin
Delete(s, i - 1, 2);
Dec(i);
end;
Dec(i);
end;
ShowMessage(s);
end;
快来帮忙啊
文字中间的空格不去。----------------------
那你调用这个过程就可以了:uses StrUtils;function QTrim(const S: String): String;
var tmp:WideString;
begin
tmp:=s;
while AnsiStartsText(' ',tmp) do tmp:=copy(tmp,2,length(tmp));
while AnsiEndsText(' ',tmp) do tmp:=copy(tmp,1,length(tmp)-1);
QTrim:=tmp;
end;
s:string;
begin
s:='你好 中 国!';
s:=StringReplace(s,' ','',[rfReplaceAll]);
showmessage( s );
end;