for the following example:
string: hello, world
char to insert: ,
result: hello,, world
algo: use indexOf to look for the char
for the following example:
string: hello, world, bye
char to insert: ,
result: hello,, world,, bye
algo: use indexOf and lastIndexOf to look for the char
for the following example:
string: hello, world, bye, world
char to insert: ,
result: hello,, wolrd,, bye,, world
algo: iterate thru the string and look for the char
My question is: for the last example, is there an easier way to insert a char to a string where there are multiple appearances of the given character to search? i mean, for the last one, since the string is short, it would be simple to iterate thru all the characters of the given string. but if you are to iterate thru a string of, say, 1000 character, it will take a long time.
tia
jacq