function TForm1.StrConvert(ConvertStr:WideString):string; var MyVar:string; i:integer; begin showmessage(InttoStr(Length(ConvertStr))); for i:=0 to Length(ConvertStr) do begin if ConvertStr[i]<>' ' then begin showmessage(ConvertStr[i]); MyVar:=MyVar+ConvertStr[i]; end; end; end;注意:string与widestring
你干脆用stringreplace吧 function DeleteSpace(s:String):String; begin result:=stringreplace(s,' ','',[rfReplaceAll,rfIgnoreCase]); end;
var
MyVar:string;
i:integer;
begin
showmessage(InttoStr(Length(ConvertStr)));
for i:=0 to Length(ConvertStr) do begin
if ConvertStr[i]<>' ' then begin
showmessage(ConvertStr[i]);
MyVar:=MyVar+ConvertStr[i];
end;
end;
end;注意:string与widestring
function DeleteSpace(s:String):String;
begin
result:=stringreplace(s,' ','',[rfReplaceAll,rfIgnoreCase]);
end;
最简单就是用StringReplace取代所有的空格