I have a string, let's say Hello world
and I need to replace the char at index 3. How can I replace a char by specifying a index?
var str = "hello world";
I need something like
str.replaceAt(0,"h");
I have a string, let's say Hello world
and I need to replace the char at index 3. How can I replace a char by specifying a index?
var str = "hello world";
I need something like
str.replaceAt(0,"h");
This method is good for small length strings but may be slow for larger text.
I did a function that does something similar to what you ask, it checks if a character in string is in an array of not allowed characters if it is it replaces it with ''
You could try
One-liner using String.replace with callback (no emoji support):
Explained:
Lets say you want to replace
Kth
index (0-based index) with'Z'
. You could useRegex
to do this.