This site is currently in read-only mode during migration to a new platform.
You cannot post questions, answers or comments, as they would be lost during the migration otherwise.
0 votes

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++.

Godot version 3.5 beta
in Engine by (210 points)

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

1 Answer

+1 vote
Best answer

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) );
      }
  }
}
by (1,646 points)
selected by

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

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.

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.

Welcome to Godot Engine Q&A, where you can ask questions and receive answers from other members of the community.

Please make sure to read Frequently asked questions and How to use this Q&A? before posting your first questions.
Social login is currently unavailable. If you've previously logged in with a Facebook or GitHub account, use the I forgot my password link in the login box to set a password for your account. If you still can't access your account, send an email to [email protected] with your username.