vb System.Text.ASCIIEncoding类(方法)实例源码

下面列出了vb System.Text.ASCIIEncoding 类(方法)源码代码实例,从而了解它的用法。

作者:VB.NET开发    项目:System.Tex   
' 导入命名空间
Imports System.Text

Class ASCIIEncodingExample
    Public Shared Sub Main()
        ' The encoding.
        Dim ascii As New ASCIIEncoding()

        ' A Unicode string with two characters outside the ASCII code range.
        Dim unicodeString As String = _
            "This Unicode string contains two characters " & _
            "with codes outside the ASCII code range, " & _
            "Pi (" & ChrW(928) & ") and Sigma (" & ChrW(931) & ")."
        Console.WriteLine("Original string:")
        Console.WriteLine(unicodeString)

        ' Save positions of the special characters for later reference.
        Dim indexOfPi As Integer = unicodeString.IndexOf(ChrW(928))
        Dim indexOfSigma As Integer = unicodeString.IndexOf(ChrW(931))

        ' Encode string.
        Dim encodedBytes As Byte() = ascii.GetBytes(unicodeString)
        Console.WriteLine()
        Console.WriteLine("Encoded bytes:")
        Dim b As Byte
        For Each b In encodedBytes
            Console.Write("[{0}]", b)
        Next b
        Console.WriteLine()

        ' Notice that the special characters have been replaced with
        ' the value 63, which is the ASCII character code for '?'.
        Console.WriteLine()
        Console.WriteLine( _
            "Value at position of Pi character: {0}", _
            encodedBytes(indexOfPi) _
        )
        Console.WriteLine( _
            "Value at position of Sigma character: {0}", _
            encodedBytes(indexOfSigma) _
        )

        ' Decode bytes back to string.
        ' Notice missing Pi and Sigma characters.
        Dim decodedString As String = ascii.GetString(encodedBytes)
        Console.WriteLine()
        Console.WriteLine("Decoded bytes:")
        Console.WriteLine(decodedString)
    End Sub
End Class


问题


面经


文章

微信
公众号

扫码关注公众号