c# - 等效于 c# 中的 python decode(string-escape)

标签 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# 中的相同字符串 s 开始,我如何才能获得相同的 base64 编码版本?

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

最佳答案

看看这些方法是否有帮助

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# 使用的通常是字符串前的 @ 符号。

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

关于c# - 等效于 c# 中的 python decode(string-escape),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17428828/

相关文章:

xcode - GCC 警告 "incompatible implicit declaration of built-in function ‘printf’“在 Mac OS X Snow Leopard 下

c# - Unity粒子系统: Change Emitter Velocity with Script

c# - 如何在 C# 中获取 Json 数组?

c# - 如何使用 ADO.NET、IDbConnection 和 IDbCommand 使 C# 代码更简洁?

python - 强制唯一与模型继承一起

python - 使用 WSGI 和 apache 安装 django

linux - 如何从独立的 GNU screen session 中邮寄命令的输出?

c# - 无法添加在 Xamarin PCL 项目中使用的程序集 System.Collections.Concurrent

python - 如何在 Elasticsearch 中启用滚动功能

windows - Windows 中 OS X VM 上的 MonoTouch?