Prev | Current Page 294 | Next

Guy Fouch?©, Trey Nash

"Accelerated VB 2008"

Sometimes, even when interfacing with other entities that use 16-bit Unicode strings,
those entities may use big-endian Unicode strings,2 whereas the Intel platform typically uses
little-endian Unicode strings. This conversion work is easy with the System.Text.Encoding
class.
This cursory example demonstrates how to convert to and from various encodings using
the Encoding objects served up by the System.Text.Encoding class:
Imports System
Imports System.Text
Imports System.Windows.Forms
Public Class EntryPoint
Shared Sub Main()
Dim leUnicodeStr As String = " ?§?¤?®?°?®???®!"
Dim leUnicode As Encoding = Encoding.Unicode
Dim beUnicode As Encoding = Encoding.BigEndianUnicode
Dim utf8 As Encoding = Encoding.UTF8
Dim leUnicodeBytes As Byte() = leUnicode.GetBytes(leUnicodeStr)
Dim beUnicodeBytes As Byte() = _
Encoding.Convert(leUnicode, beUnicode, leUnicodeBytes)
Dim utf8Bytes As Byte() = Encoding.Convert(leUnicode, utf8, leUnicodeBytes)
MessageBox.Show(leUnicodeStr, "Original String")
CHAPTER 9 n WORKING WITH STRINGS 181
2. See the Unicode FAQs at http://unicode.org/faq/utf_bom.html for an introduction to UTF encoding.
Dim sb As StringBuilder = New StringBuilder()
For Each b As Byte In leUnicodeBytes
sb.Append(b).Append(" : ")
Next
MessageBox.


Pages:
282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306
gry on line życzenia ślubne gustowne meble katowice felgi aluminiowe poznań katalog firm