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.
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);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With