假设我在 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 编码版本?
如果不清楚或需要更多信息,请告诉我
最佳答案
看看这些方法是否有帮助
System.Text.ASCIIEncoding.ASCII.GetBytes()
System.Convert.ToBase64String()
Convert.FromBase64String()
或者你可能正在寻找的是
C# 使用的通常是字符串前的 @ 符号。
如果你能澄清你的问题,那将会很有帮助
关于c# - 等效于 c# 中的 python decode(string-escape),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17428828/