I have this string: ABCDEFGHIJ
I need to replace from position 4 to position 5 with the string ZX
It will look like this: ABCZXFGHIJ
But not to use with string.replace("DE","ZX")
- I need to use with position
How can I do it?
I have this string: ABCDEFGHIJ
I need to replace from position 4 to position 5 with the string ZX
It will look like this: ABCZXFGHIJ
But not to use with string.replace("DE","ZX")
- I need to use with position
How can I do it?
You could try something link this:
Like other have mentioned the
Substring()
function is there for a reason:Also I timed this against the
StringBuilder
solution and got 900 tics vs. 875. So it is slightly slower.It's better to use the
String.substr()
.Like this:
Yet another
The easiest way to add and remove ranges in a string is to use the
StringBuilder
.An alternative is to use
String.Substring
, but I think theStringBuilder
code gets more readable.