Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

In C#, how can I replace\u0026 with &?

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#?

like image 495
leora Avatar asked Jun 24 '15 17:06

leora


People also ask

What does %= mean 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.

What is ?: operator in C?

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.

What does %d do in C?

%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.


1 Answers

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);
like image 53
vendettamit Avatar answered Sep 22 '22 17:09

vendettamit