如何将 Unicode 字符输出为一对 ASCII 字符?
如何转换(作为示例):
Señor Coconut Y Su Conjunto - 简介
:
Señor Coconut Y Su Conjunto - 简介
我有一个可以创建 m3u 播放列表的应用程序,但是当曲目文件名、艺术家或标题包含非 ASCII 字符时,音乐播放器无法正确读取该曲目,因此该曲目无法播放玩起来。
我发现,如果我将曲目写为:
#EXTINFUTF8:76,Señor Coconut Y Su Conjunto - Introducciõn
#EXTINF:76,Señor Coconut Y Su Conjunto - Introducciõn
#UTF8:01-Introducciõn.mp3
01-Introducciõn.mp3
那么音乐播放器将正确读取并播放曲目。
我的问题是我找不到正确进行转换所需的信息。
我尝试了以下操作:
byte[] byteArray = Encoding.UTF8.GetBytes(output);
foreach (Byte b in byteArray)
{
playList.Write(b);
}
where playList = new StreamWriter(filename, false);
但我只得到一系列数字输出:
#EXTINFUTF8:76,83101195177111114326711199111110117116328932831173267111110106117110116111 - 731101161141111001179999105195181110
我猜这是字符的数值而不是字符本身。
我已经有一段时间没有做过这种低级的角色操作了,我有点生疏了。
更新
我现在已经:
byte[] byteArray = Encoding.UTF8.GetBytes(output);
foreach (Byte b in byteArray)
{
playList.Write(Convert.ToChar(b));
}
进行输出,乍一看它似乎正在工作。 Notepad++ 中看到的文件显示了正确的信息。然而,第一首曲目仍未播放。
How do I convert (as an example):
Señor Coconut Y Su Conjunto - Introducciõn
to:
Señor Coconut Y Su Conjunto - Introducciõn
I've got an app that creates m3u playlists, but when the track filename, artist or title contains non ASCII characters it doesn't get read properly by the music player so the track doesn't get played.
I've discovered that if I write the track out as:
#EXTINFUTF8:76,Señor Coconut Y Su Conjunto - Introducciõn
#EXTINF:76,Señor Coconut Y Su Conjunto - Introducciõn
#UTF8:01-Introducciõn.mp3
01-Introducciõn.mp3
Then the music player will read it correctly and play the track.
My problem is that I can't find the information I need to be able to do the conversion properly.
I've tried the following:
byte[] byteArray = Encoding.UTF8.GetBytes(output);
foreach (Byte b in byteArray)
{
playList.Write(b);
}
where playList = new StreamWriter(filename, false);
but I just get a series of numbers output:
#EXTINFUTF8:76,83101195177111114326711199111110117116328932831173267111110106117110116111 - 731101161141111001179999105195181110
which I guess are the numerical values of the characters rather than the characters themselves.
It's been a while since I've done this low level character manipulation and I'm a little rusty.
UPDATE
I've now got:
byte[] byteArray = Encoding.UTF8.GetBytes(output);
foreach (Byte b in byteArray)
{
playList.Write(Convert.ToChar(b));
}
to do the output and at first glance it appeared to be working. The file as seen in Notepad++ is showing the correct information. However, the first track still isn't being played.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您希望整个流都采用 UTF-8 格式。尝试:
现在,要写入流,只需传递名为
output
的String
,如下所示:流现在都将采用正确的编码,因此您也应该能够做类似的事情:
You want the whole stream to be in UTF-8. Try:
Now, to write to the stream, just pass your
String
namedoutput
like this:The stream will now all be in the proper encoding, so you should also just be able to do something like:
好吧,尝试编写播放器期望的编码。而且是utf8! (我猜)
在你的示例中看到:
#UTF8
?well, try to write the encoding player expects. and it is utf8! (i guess)
see that:
#UTF8
in your sample?