【问题标题】:Is there a way to detect an alphanumeric Unicode symbol?有没有办法检测字母数字 Unicode 符号?
【发布时间】:2009-05-29 11:12:50
【问题描述】:

我有一个由字母、数字和标点符号组成的 Unicode 字符串。我可以使用 C++ 标准库或 Win32 API 检测数字和字母字符(不一定是 ASCII)吗?

【问题讨论】:

  • 我的帖子是否为您提供了必要的信息?

标签: c++ string winapi unicode


【解决方案1】:

iswdigit()iswalpha()iswalnum() 是您正在寻找的函数。

干杯!

【讨论】:

  • 这些不只是检查与isdigit(),isalpha(),isalnum()相同的东西吗?原始帖子似乎要求检测非拉丁数字和字母。
【解决方案2】:

另一个选项是 Win32 API 调用GetStringTypeW()

【讨论】:

    【解决方案3】:

    我推荐 ICU 图书馆。它拥有所有的 Unicode 数据,以及一个体面的 C++ Unicode 字符串类。

    【讨论】:

      【解决方案4】:

      This Microsoft documentation page 描述了正则表达式中的“Unicode 字符类”,这听起来非常相关。我认为答案在 .Net 域中,而不是纯 Win32 C++,但也许你可以挖掘一些东西。

      【讨论】:

      • 链接指向正则表达式语法参考。
      【解决方案5】:
      Private Declare Function GetStringTypeW Lib "Kernel32" (ByVal InfoType As Long, Text As Byte, ByVal Length As Long, Types As Integer) As Long
      ...
      Dim S As String, B() As Byte, C() As Integer, L as Long
      L = Len(S)
      ReDim C(1 To L)
      B = S
      If GetStringTypeW(1, B(0), L, C(1)) Then
          'Character classes are in C.
      Else
          'Something went wrong. Deal with it or call Err.Raise.
      End If
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2016-09-20
        • 2011-08-25
        • 1970-01-01
        • 2022-06-12
        • 2016-03-04
        • 2014-09-26
        • 2018-05-06
        • 2021-06-01
        相关资源
        最近更新 更多