00:00
00:00
Newgrounds Background Image Theme

MoxKatt just joined the crew!

We need you on the team, too.

Support Newgrounds and get tons of perks for just $2.99!

Create a Free Account and then..

Become a Supporter!

Insert letter into string?

364 Views | 3 Replies
New Topic Respond to this Topic

Insert letter into string? 2016-05-11 10:31:07


Hi!
I'm making a name input screen, that has lots of letters everywhere. The player can then press the arrow keys to get to that letter. When the player presses the enter key, that letter appears inside a textbox, just above all of the letters.

My question is, how could I get a letter added to a string? I've got a very faint idea; don't know if I could use appendText, split, or something else. idk. :P


I'm not that good at signatures.

Response to Insert letter into string? 2016-05-11 10:50:07


You mean adding text onto the end of a string? Just do this:

myString += "butts";

Response to Insert letter into string? 2016-05-11 10:55:49


At 5/11/16 10:50 AM, Diki wrote: You mean adding text onto the end of a string? Just do this:

myString += "butts";

Oh, thanks Diki!
I thought it would be a lot more complicated. XD


I'm not that good at signatures.

Response to Insert letter into string? 2016-05-11 11:37:32


Be aware, though, that strings are not mutable in AS3, so if you have the option of allowing the user to insert characters in the middle of the string, then you'd have to create a new string each time.

For example:

var str:String = TESTSTRING;

if I had to change the R to an S I'd have to create a new string with:

str = str.slice(0, 6) + "S" + str.slice(7);

...which actually creates 3 strings:
1) The str itself (reassigning)
2) Slicing from 0 to 6
3) Slicing from 7 to the end


Slint approves of me! | "This is Newgrounds.com, not Disney.com" - WadeFulp

"Sit look rub panda" - Alan Davies

BBS Signature