假设我在python中有这样一个函数,它接受一个字符串,然后返回它的解码结果(‘string -escape’):
def myFunc(s):
return s.decode("string-escape")
在C#中有没有类似的东西?我尝试了一些方法,比如将字符串编码为UTF-8并将其存储在字节数组中,但似乎没有一种方法能给出与python完全相同的字符串。
编辑: python用法示例:
>>> from base64 import b64encode #import base64 encode
>>> s = "x\340s5g\272m\273\252\252\344\202\312\352\275\205" #original string
>>> decoded = s.decode("string-escape")
>>> print decoded #print decoded string
x?s5g?m?????꽅
>>> print b64encode(decoded)
eOBzNWe6bbuqquSCyuq9hQ== #base 64 encoded version of the end result
那么,从C#中相同的字符串s开始,如何才能获得相同的base64编码版本呢?
如果这不清楚或需要更多信息,请让我知道
发布于 2014-02-21 17:03:46
查看这些方法是否有帮助
System.Text.ASCIIEncoding.ASCII.GetBytes()
System.Convert.ToBase64String()
Convert.FromBase64String()
或者你可能正在寻找的是
通常,c#会在字符串前使用@ symbol。
如果你能澄清你的问题,这将是有帮助的。
https://stackoverflow.com/questions/17428828
复制相似问题