Registriert seit: 2. Mär 2004
5.508 Beiträge
Delphi 5 Professional
|
Re: Alle nicht numerischen Zeichen aus String entfernen
11. Sep 2007, 14:36
Kopiert aus der JCL, Unit JclStrings:
Delphi-Quellcode:
function StrKeepChars(const S: string; const Chars: TSysCharSet): string;
{$IFDEF CLR}
var
I: Integer;
sb: StringBuilder;
begin
sb := StringBuilder.Create(Length(S));
for I := 0 to S.Length - 1 do
if AnsiChar(S[I]) in Chars then
sb.Append(S[I]);
Result := sb.ToString();
end;
{$ELSE}
var
Source, Dest: PChar;
Len, Index: Integer;
begin
Len := Length(S);
SetLength(Result, Len);
UniqueString(Result);
Source := PChar(S);
Dest := PChar(Result);
for Index := 0 to Len-1 do
begin
if Source^ in Chars then
begin
Dest^ := Source^;
Inc(Dest,SizeOf(Char));
end;
Inc(Source,SizeOf(Char));
end;
SetLength(Result, (Longint(Dest) - Longint(PChar(Result))) div SizeOf(Char));
end;
b := StrStrKeepChars(a, ['0'..'9', '.', ',']);
Andreas
|
|
Zitat
|