Is there a C# method like Python's repr() to get the true representation of the object? Suppose we have:
string identifier = "22\n44";
Console.WriteLine(identifier);
This would return
22 44
Is there a way to get
"22\n44"
In Python this is easy. We can just do repr("22\n44")
.
I thought of this question because I was trying to convert "2244"
to '2244'
using
var identifier = "2244";
identifier = identifier.Replace("\"", "'");
Console.WriteLine(identifier);
The output is just 2244
, because double quotes are for our purpose. But in my case, I did this to get what I wanted:
identifier = string.Format("'{0}'", identifier);
because initially the database was receiving the query as IN ("2244")
instead of IN ('2244')
and was throwing Invalid Number error.