如何将字符串中的 \xA0 (或非 ASCII)字符替换为 ' '?

发布于 2024-09-25 19:32:07 字数 137 浏览 0 评论 0原文

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

该文本将被输入到 MySQL 数据库中,并且不会与字符串中的这些字符一起导入。尝试发布该行时,我收到 HY000 错误的字符串值

I have an excel file with numerous Non-ASCII characters which I would like to replace with the space character.

This text is to be entered into a MySQL database, and it will not import with these characters in the strings. I get a HY000 Incorrect string value when trying to post the row.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

在巴黎塔顶看东京樱花 2024-10-02 19:32:07

如果非 Ascii 字符集是固定的,您可以使用:

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

其中 #1#4 是您要替换的非 Ascii 字符。

这里是一些有关其使用的文档。

您也可以这样做。

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;

然后可以将CharInSet中的Set更改为可接受的字符。

If the set of Non-Ascii characters is fixed you could use:

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

where #1#4 is the non-ascii characters you want to have replaced.

Here is some docs on it's use.

You could also do this.

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;

Then you can change Set in CharInSet to the acceptable characters.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文