VB.NET - Convert Unicode in one TB to Shift-JIS in another TB
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开发者_如何学JAVA.
How can I convert Unicode text to Shift-JIS when SJIS isn't available in the System.Text.Encoding types?
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:
var enc = Encoding.GetEncoding("shift-jis");
var value = enc.GetBytes("hello world");
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.
精彩评论