I do need a working ASP.NET C# code to replace characters in a string.
My following code works fine but in case of input "a" it gives me an output as "678d", but in case of input "c" the output is correct as it is i.e. "8d"... Here it automatically replaces the rest values too. I can see the code is executing in a step by step process... This results me to get an overloaded output.
{
StringBuilder builder = new StringBuilder();
builder.Replace("a", "6b");
builder.Replace("b", "7c");
builder.Replace("c", "8d");
return builder.ToString();
}
Now, I do need to replace "a" as just "6b" and it should not load the rest values.
To be more independent of the actual replacements you could do a two way replacement:
First replace the occurrences with a placeholder that will not appear in the string (like %%1%% to replace "a", %%2%% to replace "b" etc.).
Then in a second run, replace %%1%% with "8d", %%2%% with "7c" etc.
This will work in any case.