user3116971
user3116971

Reputation: 33

How to determine is character is Chinese in c++?

In python you can check a char 'c' in a condition for e.g if(c >= 0x4E00 and c <= 0x9FFF) ..and so on to determine if character is Chinese. How do we go about doing that in cpp? I have tried using (unsigned int)c and some ways to convert it to utf-8 first and try. Please suggest a way to compare a character's hex in c++.

Thanks!

Upvotes: 0

Views: 1692

Answers (2)

rici
rici

Reputation: 241861

If your string is in UTF-8 and you are using a UTF-8 locale, you can use std::mbrtoc32 to extract Unicode code points one at a time from the string. The example on the linked web page from cppreference.com shows how to do that.

If the character(s) have a different encoding, it's impossible to offer advice eithout knowing the encoding.

Upvotes: 1

schnedan
schnedan

Reputation: 282

You won't find UTF Character support in C++ (language or library), it supports normal and wide characters but no real UTF.

Maybe this can help you, as the unicode consortium itself has an open-sourced C/C++ Library which should help you to solve your conversion problem.
(http://site.icu-project.org/)

Of course, some leaner solutions can be found with the help of google easily

Upvotes: 1

Related Questions