如何将 Unicode 字符输出为一对 ASCII 字符?

发布于 2024-08-28 23:08:17 字数 1281 浏览 3 评论 0原文

如何转换(作为示例):

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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

别再吹冷风 2024-09-04 23:08:17

您希望整个流都采用 UTF-8 格式。尝试:

StreamWriter playList = new StreamWriter(filename, false, System.Text.Encoding.UTF8);

现在,要写入流,只需传递名为 outputString ,如下所示:

playList.Write(output);

流现在都将采用正确的编码,因此您也应该能够做类似的事情:

playList.WriteLine("#EXTINFUTF8:76,Señor Coconut Y Su Conjunto - Introducciõn");

You want the whole stream to be in UTF-8. Try:

StreamWriter playList = new StreamWriter(filename, false, System.Text.Encoding.UTF8);

Now, to write to the stream, just pass your String named output like this:

playList.Write(output);

The stream will now all be in the proper encoding, so you should also just be able to do something like:

playList.WriteLine("#EXTINFUTF8:76,Señor Coconut Y Su Conjunto - Introducciõn");
凯凯我们等你回来 2024-09-04 23:08:17

好吧,尝试编写播放器期望的编码。而且是utf8! (我猜)

byte[] bytesToWrite = Encoding.Utf8.GetBytes(yourString);

在你的示例中看到:#UTF8

well, try to write the encoding player expects. and it is utf8! (i guess)

byte[] bytesToWrite = Encoding.Utf8.GetBytes(yourString);

see that: #UTF8 in your sample?

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文