代码之家  ›  专栏  ›  技术社区  ›  Simon

如何将字符串中的\xa0(或非ascii)字符替换为“”?

  •  1
  • Simon  · 技术社区  · 14 年前

    我有一个Excel文件,其中包含许多非ASCII字符,我想用空格字符替换这些字符。

    此文本将被输入到MySQL数据库中,并且不会使用字符串中的这些字符导入。我得到了 HY000 Incorrect string value 当试图发布行时。

    1 回复  |  直到 9 年前
        1
  •  6
  •   Robert Love    14 年前

    NewString := StringReplace(OriginalString,#1#4,' ',[rfReplaceAll])
    

    Here is some docs on it's use.

    function StripNonAlpha(aInput : String) : String;
    var
     I : Integer;
    begin
     result := aInput;
     for I := 1 to length(result) do
     begin
       if not CharInSet(result[I],['A'..'Z','a'..'z']) then
          result[I] := ' ';
     end;
    end;