本文整理汇总了VB.NET中System.Text.Encoding类的典型用法代码示例。如果您正苦于以下问题:VB.NET Encoding类的具体用法?VB.NET Encoding怎么用?VB.NET Encoding使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Encoding类的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的VB.NET代码示例。
示例1: Example
' 导入命名空间
Imports System.Text
Module Example
Public Sub Main()
Dim enc As Encoding = Encoding.GetEncoding(1253)
Dim altEnc As Encoding = Encoding.GetEncoding("windows-1253")
Console.WriteLine("{0} = Code Page {1}: {2}", enc.EncodingName,
altEnc.CodePage, enc.Equals(altEnc))
Dim greekAlphabet As String = "Α α Β β Γ γ Δ δ Ε ε Ζ ζ Η η " +
"Θ θ Ι ι Κ κ Λ λ Μ μ Ν ν Ξ ξ " +
"Ο ο Π π Ρ ρ Σ σ ς Τ τ Υ υ " +
"Φ φ Χ χ Ψ ψ Ω ω"
Console.OutputEncoding = Encoding.UTF8
Dim bytes() As Byte = enc.GetBytes(greekAlphabet)
Console.WriteLine("{0,-12} {1,20} {2,20:X2}", "Character",
"Unicode Code Point", "Code Page 1253")
For ctr As Integer = 0 To bytes.Length - 1
If greekAlphabet(ctr).Equals(" "c) Then Continue For
Console.WriteLine("{0,-12} {1,20} {2,20:X2}", greekAlphabet(ctr),
GetCodePoint(greekAlphabet(ctr)), bytes(ctr))
Next
End Sub
Private Function GetCodePoint(ch As String) As String
Dim retVal As String = "u+"
Dim bytes() As Byte = Encoding.Unicode.GetBytes(ch)
For ctr As Integer = bytes.Length - 1 To 0 Step -1
retVal += bytes(ctr).ToString("X2")
Next
Return retVal
End Function
End Module
输出:
Character Unicode Code Point Code Page 1253 Α u+0391 C1 α u+03B1 E1 Β u+0392 C2 β u+03B2 E2 Γ u+0393 C3 γ u+03B3 E3 Δ u+0394 C4 δ u+03B4 E4 Ε u+0395 C5 ε u+03B5 E5 Ζ u+0396 C6 ζ u+03B6 E6 Η u+0397 C7 η u+03B7 E7 Θ u+0398 C8 θ u+03B8 E8 Ι u+0399 C9 ι u+03B9 E9 Κ u+039A CA κ u+03BA EA Λ u+039B CB λ u+03BB EB Μ u+039C CC μ u+03BC EC Ν u+039D CD ν u+03BD ED Ξ u+039E CE ξ u+03BE EE Ο u+039F CF ο u+03BF EF Π u+03A0 D0 π u+03C0 F0 Ρ u+03A1 D1 ρ u+03C1 F1 Σ u+03A3 D3 σ u+03C3 F3 ς u+03C2 F2 Τ u+03A4 D4 τ u+03C4 F4 Υ u+03A5 D5 υ u+03C5 F5 Φ u+03A6 D6 φ u+03C6 F6 Χ u+03A7 D7 χ u+03C7 F7 Ψ u+03A8 D8 ψ u+03C8 F8 Ω u+03A9 D9 ω u+03C9 F9