本文整理匯總了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