+1 vote

So I have a variable text where I got this input (String) from my users. I want to split the String character by character. I tried using the split method with blank divisor but it isn't working. Below is a snippet of the code.

textArray = text.split("", true);

I tried "\0" as divisor but the engine say that it's an invalid escape sequence.

Any work around?

Edit: It seem that I need to use RegEx with "(?!^)". I am still trying to figure out how to use it. Any help will be appreciated.

in Engine by (42 points)
edited by

1 Answer

+7 votes
Best answer

You can access the characters in a String like you would with a normal array:

var st = "abc"

prints a.

by (1,540 points)
selected by

Ahh. That was a nice trick. Thank you!

if you liked the answer, why not choosing it a the best answer ? it helps other people, trying to help.

Yep. I am sorry that I forgot about the "best answer" feature of Godot QA. :(.

Thanks for the reminder MrMonk.

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 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 webmaster@godotengine.org with your username.