I am getting a string in my C# code that comes from some javascript serialization and I see a bunch of strings like this:
Peanut Butter \u0026 Jelly
I tried doing this:
string results = resultFromJsonSerialization();
results = results.Replace("\u0026", "&");
return results;
and I am expecting that to change to:
Peanut Butter & Jelly
but it doesn't seem to do the replace. What is the correct way to do this replacement in C#?
%= Modulus AND assignment operator. It takes modulus using two operands and assigns the result to the left operand. C %= A is equivalent to C = C % A.
C operators are one of the features in C which has symbols that can be used to perform mathematical, relational, bitwise, conditional, or logical manipulations. The C programming language has a lot of built-in operators to perform various tasks as per the need of the program.
%d is a format specifier, used in C Language. Now a format specifier is indicated by a % (percentage symbol) before the letter describing it. In simple words, a format specifier tells us the type of data to store and print. Now, %d represents the signed decimal integer.
You can use Regex Unescape() method.
string results = resultFromJsonSerialization();
results = System.Text.RegularExpressions.Regex.Unescape(results);
return results;
You can also utilize the Server utility for HTML encode.
results = ControllerContext.HttpContext.Server.HtmlDecode(results);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With