Delphi-检查Unicode字符是否发生在一组字符中?
该代码与Delphi -7(直到Delphi获得Unicode支持)非常有用:
Value := edit1.Text[1];
if Value in ['м', 'ж'] then ...
'lim','ж' - 西里尔符号,
但这种结构与Unicode Charachter不起作用。
我尝试了很多事情,但它们不起作用。
我还尝试将值类型更改为“ char”和“ ansichar”。
不工作工作:
const
MySet : set of WideChar = [WideChar('м'), WideChar('ж')];
begin
Value := edit1.Text[1];
if Value in MySet then ...
不工作:
if AnsiChar(Value) in ['м', 'ж'] then ...
不工作:
if CharInSet(Value, ['м', 'ж']) then ...
,但这效果很好:
if (Value = 'м') or (Value = 'ж') then ...
是否有机会通过在delphi的现代版本中使用 set 来检查Unicode角色? > 还是我们应该单独检查每个角色?
我的delphi版本是10.4更新2社区版
This code works good with Delphi-7 (until Delphi had Unicode support):
Value := edit1.Text[1];
if Value in ['м', 'ж'] then ...
'м', 'ж' - cyrillic symbols
But this construction doesn't work with Unicode charachter.
I try a lot of things, but they are doesn't work.
I also tried changing the value types to "Char" and "AnsiChar".
Doesn't work:
const
MySet : set of WideChar = [WideChar('м'), WideChar('ж')];
begin
Value := edit1.Text[1];
if Value in MySet then ...
Doesn't work:
if AnsiChar(Value) in ['м', 'ж'] then ...
Doesn't work:
if CharInSet(Value, ['м', 'ж']) then ...
But this works good:
if (Value = 'м') or (Value = 'ж') then ...
Whether there is an opportunity to check up UNICODE character by use of a SET in the modern versions of Delphi?
Or should we check each character individually?
My Delphi version is 10.4 update 2 Community Edition
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
Delphi Set类型只能处理256个值,因此不能用于处理Unicode字符。对于处理unicode,
system.character
单元提供了各种方法和助手。对于这种特殊情况,您可以使用一个
isInarray()
字符助手。您不必声明一组字符,而是需要声明一系列字符:注意:Delphi Xe7引入了其他语言支持以初始化和使用动态数组,并且Square Brackets也可以用于更简单的数组初始化。在上面的示例的上下文中,
['lim',''']
不是集,而是一组宽字符。A Delphi set type can only handle a maximum of 256 values, so it cannot be used for handling Unicode characters. For handling Unicode, the
System.Character
unit provides various methods and helpers.For this particular case, there is an
IsInArray()
character helper you can use. Instead of declaring a set of characters, you will need to declare an array of characters:Note: Delphi XE7 introduced additional language support for initializing and working with dynamic arrays, and square brackets can also be used for simpler array initialization. In the context of above example,
['м', 'ж']
is not a set, but an array of wide characters.您的意思是delphi set ?
通常,不可能拥有x 的
集,其中基本类型
word 一组都不可能。由于有256 * 256个不同的角色值,因此不可能拥有一组宽字符。 (如果确实可以的话,这种集合类型的变量的大小为8 kb。这将是一个异常大的变量。)x
具有超过256个可能的不同值。因此由于没有“ delphi of of delphi unicode字符”之类的东西,所以问题“如何”查看字符是否属于Delphi unicode字符集“没有意义”。
还是您只是指数学集?
如果是这样,这当然是可能的,但是您不能使用Delphi集来表示数学集。相反,您需要使用其他一些数据类型。一种可能性是一个简单的数组,如果您不介意其O(n)特征。
Do you mean a Delphi set?
In general, it is impossible to have a
set of X
where the base typeX
has more than 256 possible distinct values. Soset of Byte
is fine, butset of Word
isn't possible. Since there are 256 * 256 distinct wide character values, it is therefore impossible to have a set of wide characters. (If this were indeed possible, a variable of such a set type would be 8 kB in size. That would be an unusually large variable.)Since there is no such thing as "Delphi set of Unicode characters", the question "How to see if a character belongs to a Delphi set of Unicode characters" doesn't make sense.
Or do you simply mean a mathematical set?
If so, of course this is possible, but you cannot use a Delphi set to represent the mathematical set of characters. Instead, you need to use some other data type. One possibility is a simple array, if you don't mind its O(n) characteristics.