要去掉中間的空白,就要使用
function StringReplace ( const SourceString, OldPattern, NewPattern : string; Flags : TReplaceFlags ) : string
範例:把a改成the
var
before, after : string;
begin
// Try to replace all occurrences of a or A to THE
before := 'This is a way to live A big life';
after := StringReplace(before, ' a ', ' THE ',
[rfReplaceAll, rfIgnoreCase]);
ShowMessage('Before = '+before);
ShowMessage('After = '+after);
end;
也可以用正則表示法來去空白..
回覆刪除System.RegularExpressions
var regex:Tregex;
str:='dsf dsaf sdf sdaf ads as s';
RegEx := TRegEx.Create('\s+'); //使用正則表示法去空白跟換行符號
str:=Regex.Replace(str, '');
showmessage(str);