【发布时间】:2010-10-01 02:54:05
【问题描述】:
我有一个包含许多非 ASCII 字符的 excel 文件,我想用空格字符替换它们。
此文本将被输入到 MySQL 数据库中,并且不会在字符串中包含这些字符。我在尝试发布该行时收到 HY000 Incorrect string value。
【问题讨论】:
标签: delphi string non-ascii-characters
我有一个包含许多非 ASCII 字符的 excel 文件,我想用空格字符替换它们。
此文本将被输入到 MySQL 数据库中,并且不会在字符串中包含这些字符。我在尝试发布该行时收到 HY000 Incorrect string value。
【问题讨论】:
标签: delphi string non-ascii-characters
如果非 Ascii 字符集是固定的,您可以使用:
NewString := StringReplace(OriginalString,#1#4,' ',[rfReplaceAll])
其中 #1#4 是您要替换的非 ascii 字符。
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;
然后你可以将 CharInSet 中的 Set 更改为可接受的字符。
【讨论】: