Char.IsSymbol("*") 为假 [英] Char.IsSymbol("*") is false

查看:26
本文介绍了Char.IsSymbol("*") 为假的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在研究密码验证例程,并惊讶地发现 VB 没有将*"视为每个 Char.IsSymbol() 检查的符号.这是 QuickWatch 的输出:

I'm working on a password validation routine, and am surprised to find that VB does not consider '*' to be a symbol per the Char.IsSymbol() check. Here is the output from the QuickWatch:

char.IsSymbol("*")  False   Boolean

MS 文档 没有指定 IsSymbol 匹配哪些字符,但确实暗示了该标准数学符号包含在此处.

The MS documentation does not specify what characters are matched by IsSymbol, but does imply that standard mathematical symbols are included here.

有没有人有匹配所有标准美国特殊字符的好主意?

Does anyone have any good ideas for matching all standard US special characters?

推荐答案

在此上下文中作为符号的字符:UnicodeCategory.MathSymbol, UnicodeCategory.CurrencySymbol, System.Globalization 命名空间中的 UnicodeCategory.ModifierSymbol 和 UnicodeCategory.OtherSymbol.这些是分别指定为 Sm、Sc、Sk 和 So 的 Unicode 字符.所有其他字符返回 False.

Characters that are symbols in this context: UnicodeCategory.MathSymbol, UnicodeCategory.CurrencySymbol, UnicodeCategory.ModifierSymbol and UnicodeCategory.OtherSymbol from the System.Globalization namespace. These are the Unicode characters designated Sm, Sc, Sk and So, respectively. All other characters return False.

来自 .Net 来源:

From the .Net source:

internal static bool CheckSymbol(UnicodeCategory uc)
{
    switch (uc)
    {
        case UnicodeCategory.MathSymbol:
        case UnicodeCategory.CurrencySymbol:
        case UnicodeCategory.ModifierSymbol:
        case UnicodeCategory.OtherSymbol:
            return true;
        default:
            return false;
    }
}

或转换为 VB.Net:

or converted to VB.Net:

Friend Shared Function CheckSymbol(uc As UnicodeCategory) As Boolean
    Select Case uc
        Case UnicodeCategory.MathSymbol, UnicodeCategory.CurrencySymbol, UnicodeCategory.ModifierSymbol, UnicodeCategory.OtherSymbol
            Return True
        Case Else
            Return False
    End Select
End Function

CheckSymbolIsSymbol 使用给定字符的 Unicode 类别调用.

CheckSymbol is called by IsSymbol with the Unicode category of the given char.

由于 * 属于 OtherPunctuation 类别(您可以使用 char.GetUnicodeCategory() 进行检查),因此它不被视为符号,方法正确返回False.

Since the * is in the category OtherPunctuation (you can check this with char.GetUnicodeCategory()), it is not considered a symbol, and the method correctly returns False.

回答您的问题:使用 char.GetUnicodeCategory() 检查字符属于哪个类别,并决定是否将其包含在您自己的逻辑中.

To answer your question: use char.GetUnicodeCategory() to check which category the character falls in, and decide to include it or not in your own logic.

这篇关于Char.IsSymbol("*") 为假的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆