本文整理自网络,侵删。
type
TCharSet = set of Char;
function StripNonConforming(const S: string;
const ValidChars: TCharSet): string;
var
DestI: Integer;
SourceI: Integer;
begin
SetLength(Result, Length(S));
DestI := 0;
for SourceI := 1 to Length(S) do
if S[SourceI] in ValidChars then
begin
Inc(DestI);
Result[DestI] := S[SourceI]
end;
SetLength(Result, DestI)
end;
function StripNonNumeric(const S: string): string;
begin
Result := StripNonConforming(S, ['0'..'9'])
end;
相关阅读 >>
Delphi comparestr 这个函数可以模糊匹配,且不区分大小写
Delphi实现进制转化(2进制,8进制,10进制,16进制)
更多相关阅读请进入《Delphi》频道 >>