delphi - strip out all non standard text characers from string

前端 未结 6 1376
-上瘾入骨i
-上瘾入骨i 2021-02-13 14:52

I need to strip out all non standard text characers from a string. I need remove all non ascii and control characters (except line feeds/carriage returns).

6条回答
  •  予麋鹿
    予麋鹿 (楼主)
    2021-02-13 15:19

    my performance solution;

    function StripNonAnsiChars(const AStr: String; const AIgnoreChars: TSysCharSet): string;
    var
      lBuilder: TStringBuilder;
      I: Integer;
    begin
      lBuilder := TStringBuilder.Create;
      try
        for I := 1 to AStr.Length do
          if CharInSet(AStr[I], [#32..#127] + AIgnoreChars) then
            lBuilder.Append(AStr[I]);
        Result := lBuilder.ToString;
      finally
        FreeAndNil(lBuilder);
      end;
    end;
    

    I wrote by delphi xe7

提交回复
热议问题