在unicode中过滤非可键入字符

时间:2014-05-29 14:55:48

标签: delphi unicode delphi-2010

在Delphi 6(非Unicode平台)下编写的旧应用程序中,我过去只是通过引用ANSI字符表中的单元格数来过滤掉不可键入的字符( if(#32中的aKeyChar)。 。#254])然后.... )。

现在我转移到Delphi 2010,其中平台基于Unicode,这些字符映射不再相关。在Delphi 2010中有没有一种干净的方法来实现这一目标?

2 个答案:

答案 0 :(得分:2)

查看System.Character单元中的各种辅助函数,例如GetUnicodeCategory()IsControl()IsLetterOrDigit()IsWhiteSpace()等。

答案 1 :(得分:1)

在Unicode中,要确定代码点是否为控制字符(假设您的意思是" typeable"),那么查看该值是否在集合中是不够的。要获取"控制字符",您可以查看System.Character类:

if Character.IsControl(aKeyChar) then

但请注意,您可能必须检查WideChar是否也是低代理或高代理,例如。

if Character.IsLowSurrogate(aKeyChar) then
  // is unprintable in and of itself and next WideChar must be a high surrogate.
  // the combination is printable.

请注意,可以再次打印代理对(低代理+高代理)。单独的低代理不可打印。