I've got an extension method that converts me ulong
into a string value with some kind of encryption. I want to output them as they are just by using Console.WriteLine
, in most scenarios it works but there is a problem with values with escapes characters. For example "(V\\\|RN"
outputs just "(V\|RN"
.
var result = id.IdToCode();
Console.WriteLine(result);
or
Console.WriteLine(id.IdToCode());
The method IdToCode
returns stringBuilder.ToString()
I've tried many combinations with putting somewhere @
to return the string as it is but without any result. Maybe I should override the default behavior of Console.WriteLine
or the stringBuilder.ToString()
is the problem here?
Here is a screen of what I mean.
And below the code of IdToCode
method:
public static string IdToCode(this ulong value)
{
const string charArray = @"1234890qwertyuiopbnmQWERTYUasdfghjklzxcvIOPASDFGHJKLZXCVBNM!+={}[]|\<>?@#567$%^&*()-_";
StringBuilder stringBuilder = new StringBuilder();
ulong num = value;
while (num != 0UL)
{
ulong index = num % (ulong)charArray.Length;
num /= (ulong)charArray.Length;
stringBuilder.Insert(0, charArray[(int)index].ToString());
}
return stringBuilder.ToString();
}
I've changed the char array into different one but the general method it's the same as above.