0 votes

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.

asked May 13, 2017 in Projects by inTech (40 points)
edited May 13, 2017 by inTech

1 Answer

+3 votes
Best answer

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

var st = "abc"

prints a.

answered May 13, 2017 by mollusca (1,506 points)
selected May 17, 2017 by inTech

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.