delphi-从字符串中删除所有非标准文本字符 [英] delphi - strip out all non standard text characers from string
本文介绍了delphi-从字符串中删除所有非标准文本字符的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我需要从字符串中去除所有非标准文本字符.我需要删除所有非ascii和控制字符(换行符/回车符除外).
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).
推荐答案
应该执行以下操作:
// For those who need a disclaimer:
// This code is meant as a sample to show you how the basic check for non-ASCII characters goes
// It will give low performance with long strings that are called often.
// Use a TStringBuilder, or SetLength & Integer loop index to optimize.
// If you need really optimized code, pass this on to the FastCode people.
function StripNonAsciiExceptCRLF(const Value: AnsiString): AnsiString;
var
AnsiCh: AnsiChar;
begin
for AnsiCh in Value do
if (AnsiCh >= #32) and (AnsiCh <= #127) and (AnsiCh <> #13) and (AnsiCh <> #10) then
Result := Result + AnsiCh;
end;
对于 UnicodeString
,您可以执行类似的操作.
For UnicodeString
you can do something similar.
这篇关于delphi-从字符串中删除所有非标准文本字符的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文