VB.NET - 将一个 TB 中的 Unicode 转换为另一个 TB 中的 Shift-JIS
尝试开发一个文本编辑器,我有两个文本框,每个文本框下面都有一个按钮。
当按下 textbox1 下面的按钮时,它应该将 Unicode 文本(原本是日语)转换为 Shift-JIS。
我这样做的原因是因为VOCALOID2软件只允许将ANSI和Shift-JIS编码的文本粘贴到歌词系统中。该应用程序的用户通常已将键盘设置为日语,但它输入的是 Unicode。
当 SJIS 在 System.Text.Encoding 类型中不可用时,如何将 Unicode 文本转换为 Shift-JIS?
Trying to develop a text editor, I've got two textboxes, and a button below each one.
When the button below textbox1 is pressed, it is supposed to convert the Unicode text (intended to be Japanese) to Shift-JIS.
The reason why I am doing this is because the software VOCALOID2 only allows ANSI and Shift-JIS encoding text to be pasted into the lyrics system. Users of the application normally have their keyboard set to change to Japanese already, but it types in Unicode.
How can I convert Unicode text to Shift-JIS when SJIS isn't available in the System.Text.Encoding types?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
值得庆幸的是,这不是它的工作方式。只要您在 .NET 程序中操作文本(包括 TextBox.Text 属性),就只有一种编码,即 UTF-16。当你需要与外界打交道时,无论是文件还是P/Invoked函数,那么你需要在Shift-Jis和UTF-16之间进行转换。这非常简单:
将“value”的值传递给任何需要 Shift-JIS 编码值的代码。确保它不是一个 TextBox,它不知道如何显示字节,它只知道 UTF-16。
Thankfully, that is not the way it works. As long as you are manipulating text in a .NET program, including the TextBox.Text property, there is only one encoding, UTF-16. When you need to work with the outside world, whether it is a file or a P/Invoked function, then you need to convert between Shift-Jis and UTF-16. Which is pretty straight forward:
Pass the value of "value" to whatever code needs the Shift-JIS encoded value. Make sure it is not a TextBox, it doesn't know how to display bytes, it only knows UTF-16.