5

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.

1 Answer 1

14

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);
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.