Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/314.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/361.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 相当于c语言中的python解码(字符串转义)#_C#_Python_Macos_Encoding_Decoding - Fatal编程技术网

C# 相当于c语言中的python解码(字符串转义)#

C# 相当于c语言中的python解码(字符串转义)#,c#,python,macos,encoding,decoding,C#,Python,Macos,Encoding,Decoding,假设我在python中有一个函数,它接受一个字符串并只返回该字符串的解码('string-escape'): 在C#中是否有与此等价的词?我尝试了一些方法,比如将字符串编码为UTF-8并将其存储在字节数组中,但似乎没有任何东西能提供与python完全相同的字符串 编辑: python使用示例: >>> from base64 import b64encode #import base64 encode >>> s = "x\340s5g\272m\27

假设我在python中有一个函数,它接受一个字符串并只返回该字符串的解码('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#使用字符串前的@符号


如果你能澄清你的问题,这将是一个很有帮助的

有趣的问题-也许值得展示python为此输出了什么,这样只有C语言的开发人员才有更多的上下文。
s.decode(“字符串转义”)
应该生成一个适合在Python源代码中作为字符串文本的字符串。您想用C#取消Python字符串文本的转义吗?在C#中,Base 64编码足够简单,但我认为没有内置编码器可以解码Python的字符串转义格式。您必须自己编写该部分,然后使用Convert.ToBase64String获得base64编码版本。嗯……您知道关于如何解码Python的字符串转义格式的任何有用的来源吗?从我的搜索中,我能找到的只是在字符串中使用转义字符的示例
System.Text.ASCIIEncoding.ASCII.GetBytes()

System.Convert.ToBase64String()

Convert.FromBase64String()