cannot identify string encoding
What encoding do I need to use to encode 开发者_开发百科the string document.write('website%40site.com');
so that it will look like the string below?
%64%6f%63%75%6d%65%6e%74%2e%77%72%69%74%65%28%27%3c%61%20%68%72%65%66%3d%5c%22%6d%61%69%6c%74%6f%3a%63%68%75%6d%61%6b%73%68%6c%69%61%68%40%6d%61%69%6c%2e%72%75%5c%22%3e%63%68%75%6d%61%6b%73%68%6c%69%61%68%40%6d%61%69%6c%2e%72%75%3c%5c%2f%61%3e%27%29%3b
This is normal encoded ASCII:
%3c%5c%2f%61%3e = <\/a>
and it is rare to see ASCII encoded like this, Unicode on the other hand is not.
That is the same type of encoding as URL encoding, except that all characters are encoded instead of only the ones that actually need encoding. Each byte is converted into a two digit hexadecimal number, prefixed with %
.
You can encode the string using UTF-8, then convert each byte to a hex code:
string encoded = String.Concat(
Encoding.UTF8.GetBytes("document.write('website%40site.com');")
.Select(b => "%" + b.ToString("x2"))
.ToArray()
);
That's either ASCII or UTF-8 or one of the 8 bit supersets of ASCII. Impossible to say for sure.
Your best bet is to read the documentation of whatever function or program you are trying to pass it to.
Here is an online encoder/decoder which does what you want.
精彩评论