本文整理汇总了VB.NET中System.Text.UTF32Encoding.GetString方法的典型用法代码示例。如果您正苦于以下问题:VB.NET UTF32Encoding.GetString方法的具体用法?VB.NET UTF32Encoding.GetString怎么用?VB.NET UTF32Encoding.GetString使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.Text.UTF32Encoding 的用法示例。
在下文中一共展示了UTF32Encoding.GetString方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的VB.NET代码示例。
示例1: Main
' 导入命名空间
Imports System.Text
Public Module Example
Public Sub Main()
' Create two instances of UTF32Encoding: one with little-endian byte order and one with big-endian byte order.
Dim u32LE As New UTF32Encoding(False, True, True)
Dim u32BE As New UTF32Encoding(True, True, True)
' Create byte arrays from the same string containing the following characters:
' Latin Small Letter Z (U+007A)
' Latin Small Letter A (U+0061)
' Combining Breve (U+0306)
' Latin Small Letter AE With Acute (U+01FD)
' Greek Small Letter Beta (U+03B2)
Dim str As String = "za" + ChrW(&h0306) + ChrW(&h01FD) + ChrW(&h03B2)
' barrBE uses the big-endian byte order.
Dim barrBE(u32BE.GetByteCount(str) - 1) As Byte
u32BE.GetBytes(str, 0, str.Length, barrBE, 0)
' barrLE uses the little-endian byte order.
Dim barrLE(u32LE.GetByteCount(str) - 1) As Byte
u32LE.GetBytes(str, 0, str.Length, barrLE, 0)
' Decode the byte arrays.
Console.WriteLine("BE array with BE encoding:")
DisplayString(barrBE, u32BE)
Console.WriteLine()
Console.WriteLine("LE array with LE encoding:")
DisplayString(barrLE, u32LE)
Console.WriteLine()
' Decode the byte arrays using an encoding with a different byte order.
Console.WriteLine("BE array with LE encoding:")
Try
DisplayString(barrBE, u32LE)
Catch e As ArgumentException
Console.WriteLine(e.Message)
End Try
Console.WriteLine()
Console.WriteLine("LE array with BE encoding:")
Try
DisplayString(barrLE, u32BE)
Catch e As ArgumentException
Console.WriteLine(e.Message)
End Try
Console.WriteLine()
End Sub
Public Sub DisplayString(bytes As Byte(), enc As Encoding )
' Display the name of the encoding used.
Console.Write("{0,-25}: ", enc.ToString())
' Decode the bytes and display the characters.
Console.WriteLine(enc.GetString(bytes, 0, bytes.Length))
End Sub
End Module
开发者ID:VB.NET开发者,项目名称:System.Text,代码行数:60,代码来源:UTF32Encoding.GetString 输出:
BE array with BE encoding:
System.Text.UTF32Encoding: zăǽβ
LE array with LE encoding:
System.Text.UTF32Encoding: zăǽβ
BE array with LE encoding:
System.Text.UTF32Encoding: Unable to translate bytes [00][00][00][7A] at index 0 from specified code page to Unicode.
LE array with BE encoding:
System.Text.UTF32Encoding: Unable to translate bytes [7A][00][00][00] at index 0 from specified code page to Unicode.
示例2: Example
' 导入命名空间
Imports System.Text
Module Example
Public Sub Main()
Dim utf32 As New UTF32Encoding(Not BitConverter.IsLittleEndian, True)
Dim s As String = "It was the best of times, it was the worst of times..."
' We need to dimension the array, since we'll populate it with 2 method calls.
Dim bytes(utf32.GetByteCount(s) + utf32.GetPreamble().Length - 1) As Byte
' Encode the string.
Array.Copy(utf32.GetPreamble(), bytes, utf32.GetPreamble().Length)
utf32.GetBytes(s, 0, s.Length, bytes, utf32.GetPreamble().Length)
' Decode the byte array.
Dim s2 As String = utf32.GetString(bytes, 0, bytes.Length)
Console.WriteLine(s2)
End Sub
End Module
开发者ID:VB.NET开发者,项目名称:System.Text,代码行数:20,代码来源:UTF32Encoding.GetString 输出:
?It was the best of times, it was the worst of times...
注:本文中的System.Text.UTF32Encoding.GetString方法示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论