如何在vb.net中转换unicode? [英] how can convert unicode in vb.net?

查看:367
本文介绍了如何在vb.net中转换unicode?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

亲爱的所有



i Am尝试在富文本框中写一个文本,有一些代码,然后它是同一个电子邮件端

i意味着它需要Unicode转换器请在vb.net中如何实现



Dear All

i Am Try to write a text in rich text box there is come some code and then it same email side
i mean it need Unicode converter please how its possible in vb.net

Dim myBytes As Byte() = System.Text.Encoding.Unicode.GetBytes(TextBox1.Text)

Dim myChars As Char() = System.Text.Encoding.Unicode.GetChars(myBytes)
Dim myString As String = New String(myChars)
myString = RichTextBox1.Text





i试过这个但不能正常工作



i tried this but not able to works

推荐答案

基本上,这是合作正确的代码。



我认为你的问题是没有看到它是正确的。如果你比较 myString RichTextBox1.Text (你的最后一行是赋值,请注意VB赋值和比较运算符使用相同的'='字符,所以编译器根据上下文决定它是什么。



所以,你的转换进行了往返,这两个字符串在往返之前应该是平等的。当然,最后一个赋值会丢弃计算字符串的前一行的结果。您只是没有查看实验结果,但在调试器下您会看到它是正确的。



另一个问题可能是误解了Unicode的工作原理。首先,由于System.Text.Encoding.Unicode中丑陋的Windows行话术语Unicode,很多人都感到困惑。 System.Text.Encoding.Unicode实际上不是Unicode。这是UTF-16LE,一种默认的UTF,用于在Windows内存中显示Unicode字符串。事实上,所有的UTF都不同但功能相同。它们使用1到4个字节来表示单个字符,并使用不同的方法查看与字符之间的边界对应的字节边界。 UTF-16使用一个或两个16位字来表示单个字符。你可以在 http://unicode.org/ [ ^ ]和维基百科。



-SA
Basically, this is correct code.

I think your problem is just not seeing that it is correct. If you compare myString and RichTextBox1.Text (your last line is assignment, note that VB assignment and comparison operator use the same '=' character, so the compiler "decides" what it is based on the context).

So, your conversions made a round trip, and these two strings should be equal before the round trip. Of course, the very last assignment discards the result of the previous line where you calculate the string. You are just not checking up the result of your experiment, but under debugger you would see that it is correct.

Another problem might be misunderstanding of how Unicode works. First of all, due to the ugly Windows jargon term "Unicode" in "System.Text.Encoding.Unicode" many are get confused. "System.Text.Encoding.Unicode" is not actually "Unicode". This is UTF-16LE, a default UTF used for presentation of Unicode strings in Windows memory. In fact, all UTFs are different but functionally equivalent. They use 1 to 4 bytes to represent a single character and different methods of seeing where the byte boundaries which correspond to the boundaries between characters. UTF-16 uses one or two 16-bit words to represent a single character. You can find it all in http://unicode.org/[^] and Wikipedia.

—SA


如果你写:

RichTextBox1.text = myString

将起作用
if you write :
RichTextBox1.text=myString
will working


这篇关于如何在vb.net中转换unicode?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆