Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Insert in string AS3

I need to insert string in another string in specific index.

var str1:String = "A";

var str2:String = "LoremIpsum";

I need str2 to be "LoremAIpsum", insert str1 in index 5 in str2. Thanks.

like image 414
mokayyali Avatar asked Nov 28 '11 15:11

mokayyali


1 Answers

Strings are immutable in AS3. So you cannot insert in a string. You need to get the substrings and create a new string.

var str1:String = "A";
var str2:String = "LoremIpsum";
var index:int = 5;
var str3:String = str2.slice(0, index) + str1 + str2.slice(index);
trace(str3);
like image 110
taskinoor Avatar answered Sep 19 '22 03:09

taskinoor