相关疑难解决方法(0)

Unicode字符串的跨平台迭代(使用ICU计算字母)

我想迭代Unicode字符串的每个字符,处理每个代理对并将字符序列组合为一个单元(一个字形).

文本"नमस्ते"由代码点组成:U+0928, U+092E, U+0938, U+094D, U+0924, U+0947其中,U+0938并且U+0947组合标记.

static void Main(string[] args)
{
    const string s = "??????";

    Console.WriteLine(s.Length); // Ouptuts "6"

    var l = 0;
    var e = System.Globalization.StringInfo.GetTextElementEnumerator(s);
    while(e.MoveNext()) l++;
    Console.WriteLine(l); // Outputs "4"
}
Run Code Online (Sandbox Code Playgroud)

所以我们在.NET中有它.我们也有Win32的CharNextW()

#include <Windows.h>
#include <iostream>
#include <string>

int main()
{
    const wchar_t * s = L"??????";

    std::cout << std::wstring(s).length() << std::endl; // Gives "6"

    int l = 0;
    while(CharNextW(s) != …
Run Code Online (Sandbox Code Playgroud)

c++ unicode cross-platform icu

20
推荐指数
1
解决办法
3992
查看次数

标签 统计

c++ ×1

cross-platform ×1

icu ×1

unicode ×1