我有一些错误解码的文本片段。它被解码,如cp866,但实际上它应该是utf-8("нажал кабан на баклажан"
→"╨╜╨░╨╢╨░╨╗ ╨║╨░╨▒╨░╨╜ ╨╜╨░ ╨▒╨░╨║╨╗╨░╨╢╨░╨╜"
)。我想解决这个问题,我已经写在的Python代码解决了任务:字节解码在D
broken = "╨╜╨░╨╢╨░╨╗ ╨║╨░╨▒╨░╨╜ ╨╜╨░ ╨▒╨░╨║╨╗╨░╨╢╨░╨╜"
fixed = bytes(broken, 'cp866').decode('utf-8')
print(fixed) # it will print 'нажал кабан на баклажан'
然而,一开始我是想在d来解决这个问题,但没有成功找到答案。那么,如何在D中解决这个问题呢?
[std.encoding(http://dlang.org/phobos/std_encoding.html)会有帮助,但它并不像CP866支持 –