I want to replace some characters with others i have asked a question like this before here and they recommend to use function Replace,but when i used Replace it falls in specific condition when i try replace chars with another char it removes another char that is also in a string and i don’t want to remove.here is my code for more clarification
for (int i = 0; i < words.Length; i++)
{
for (int j = 1; j < words[i].Length; j++)
{
if (j + 2 == words[i].Length)
break;
if (words[i][j] == words[i][j + 2] && words[i][j + 1] == '0')
{
words[i] = words[i].Replace(words[i][j + 1].ToString(), string.Empty);
}
}
}
if my string was “a1010” according to my code the final string should be a110 but the output is a11,i wonder why it removes the final 0??
basically resolves to…
(at least in the particular iteration you are describing)
which is replacing all 0’s in your string with empty string. If you know the exact index of the character you want to remove you can just do this…