Hello!
I’d like to know how to substitute characters of strings.
Let’s say I have…
my_str=“Hello, Johny!, hello Dolly!”;
I want to substitute all “!” characters to “?”. How do we do this?
I am assuming that first we need to know the character position of the character we want to get rid of.
(we would loop this whole 3 step process until no more “!” characters were found in the string)
- my_str.indexOf("!"); returns 12
[COLOR=DarkOrange]2) Now…how do I delete that character?[/COLOR] - The next step from there would probably be to use one of the methods String.substring() or String.slice to introduce the new character “?”;
What’s the best way to do this?