我想迭代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)