function StrsToStr(Str: string): string; //格式字符串 (取掉'#','0') var i,j:integer; begin Result:=''; j:=Length(str); for i:=1 to j do begin if not (str[i] in ['#','0']) then // 可以任意变,需要取掉的字符 Result:=Result+str[i]; end; end;
这个方法不行,你可以分别取length看看,是一样的
如果是针对'asdf'#0#0#0的话,楼上的办法好像不行... var s :String; begin s := 'asdf'#0#0#0; ShowMessage(IntTOStr(Length(s))); // 显示7 s := StrsToStr(s); // 使用楼上的函数 ShowMessage(IntTOStr(Length(s))); // 显示7 end; -------------- var s :String; begin s := 'asdf'#0#0#0; ShowMessage(IntTOStr(Length(s))); // 显示7 s := StrPas(PChar(s)); //用指针 ShowMessage(IntTOStr(Length(s))); // 显示4 end; -------------- 对于其它的字符如#13则楼上的方法可以... 也可以用StringReplace函数...
用trim函数。 试用以下代码: var s:string; s1:string; begin s:='asdf'#0#0#0; s1:='asdf'; if s=s1 then showmessage('ok') else showmessage('false'); s:=trim(s); if s=s1 then showmessage('ok') else showmessage('false');
var i,j:integer;
begin
Result:='';
j:=Length(str);
for i:=1 to j do
begin
if not (str[i] in ['#','0']) then // 可以任意变,需要取掉的字符
Result:=Result+str[i];
end;
end;
var
s :String;
begin
s := 'asdf'#0#0#0;
ShowMessage(IntTOStr(Length(s))); // 显示7
s := StrsToStr(s); // 使用楼上的函数
ShowMessage(IntTOStr(Length(s))); // 显示7
end;
--------------
var
s :String;
begin
s := 'asdf'#0#0#0;
ShowMessage(IntTOStr(Length(s))); // 显示7
s := StrPas(PChar(s)); //用指针
ShowMessage(IntTOStr(Length(s))); // 显示4
end;
--------------
对于其它的字符如#13则楼上的方法可以...
也可以用StringReplace函数...
试用以下代码:
var
s:string;
s1:string;
begin
s:='asdf'#0#0#0;
s1:='asdf';
if s=s1 then
showmessage('ok')
else
showmessage('false');
s:=trim(s);
if s=s1 then
showmessage('ok')
else
showmessage('false');