tags:

views:

149

answers:

1

hello all,

can you please help me with this issue the String class does not have insert method it has only replace :( .

what I need is: - if I have string "I stackoverflow" - I need to insert "love " at index 2 to have "I love stackoverflow"

so what I need is insertAt(index, String)

thanks

+2  A: 

You can build one of your own. Split the string and concatenate all characters before the index position with the characters of the string you want to insert and with the characters after the index.

eg:

String s = "I stackoverflow";
int index = s.indexOf(" ");
String toInsert = "love ";
String mys = s.substring(0, index) + toInsert + s.substring(index, s.length);
thelost