c#中python解码(string-escape)的等价物

时间:2013-07-02 14:53:55

标签: c# python macos encoding decoding

假设我在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#中的相同字符串开始,我怎样才能获得相同的base64编码版本?

如果这不清楚或需要更多信息,请告诉我

1 个答案:

答案 0 :(得分:1)

查看这些方法是否有帮助

System.Text.ASCIIEncoding.ASCII.GetBytes()

System.Convert.ToBase64String()

Convert.FromBase64String()

或者您可能正在寻找的是

https://stackoverflow.com/questions/11584148/how-to-convert-a-string-containing-escape-characters-to-a-string

字符串前面的@符号通常是c#使用的符号。

如果您能澄清您的问题,那将会很有帮助

相关问题