[GDNative] How do I iterate through the characters in a String using wchar_t

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By hidemat

I have a variable of type string String term = String("にほん") and I want to check if any of its characters is in the japanese hiragana charater set. Something like this:

for (auto c : term) {
   if (c >= '\u3040' && c <= '\u309f') {
       return true;

How do I do this the godot way in GDNative c++, ideally using String?

I tried doing it with std:string and std:wstring but I don’t quiet know how to deal with UTF8 characters in c++.

excellent question, I also have the problem
I follow the topic

Arthuru | 2022-02-27 00:45

:bust_in_silhouette: Reply From: sash-rc

There’s a operator and length function for a String.

  String term = "にほん";
  for (int i = 0; i < term.length(); i++) {
    auto& c = term[i];
     if (c >= L'\u3040' && c <= L'\u309f') {
       Godot::print("{0} :: {1}", i, String(c) );

Nice thank you! I see the L operator. C++ is soo weird.

hidemat | 2022-02-26 19:45

It’s a normal literal constant modifier.

C++ is not weird, it’s designed to be close to a hardware, so you need to explicitly distinguish between different-sized byte sequences.

sash-rc | 2022-02-26 20:05

Well yea it’s weird to me, because I’m just now starting to learn about it, but I totally understand the place c++ has, that’s why I’m trying to learn it. Thanks, you really helped me out.

hidemat | 2022-02-26 23:54