如何将ubyte []解码为指定的编码? [英] how to decode ubyte[] to a specified encoding?
问题描述
问题是:在运行时设置编码时如何解析文件?
The problem is: how to parse a file when encoding is set at runtime?
编码可能是: utf- 8 , utf-16 , latin1 或 other
目标是将ubyte []从所选编码转换为字符串。因为当您使用std.stdio.File.byChunk或std.mmFile.MmFile时,您具有ubyte []作为数据。
The goal it is to convert ubyte[] to a string from the selected encoding. Because when you use std.stdio.File.byChunk or std.mmFile.MmFile you have ubyte[] as data.
推荐答案
您是否正在尝试将文本文件转换为utf-8?
如果答案为是,则Phobos专门具有以下功能: @trusted string toUTF8(char [] s)
。
有关详细信息,请参见 http://dlang.org/phobos/std_utf.html 。
Are you trying to convert text file to utf-8?
If answer is 'yes', Phobos have function specialy for this: @trusted string toUTF8(in char[] s)
.
See http://dlang.org/phobos/std_utf.html for details.
很抱歉,如果您不需要的话。
Sorry if it not what you need.
这篇关于如何将ubyte []解码为指定的编码?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!