当前位置: 首页>>代码示例>>VB.NET>>正文


VB.NET Convert.FromBase64String方法代码示例

本文整理汇总了VB.NET中System.Convert.FromBase64String方法的典型用法代码示例。如果您正苦于以下问题:VB.NET Convert.FromBase64String方法的具体用法?VB.NET Convert.FromBase64String怎么用?VB.NET Convert.FromBase64String使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在System.Convert的用法示例。


在下文中一共展示了Convert.FromBase64String方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的VB.NET代码示例。

示例1: Example

Module Example
   Public Sub Main()
       ' Define a byte array.
       Dim bytes As Byte() = { 2, 4, 6, 8, 10, 12, 14, 16, 18, 20 }
       Console.WriteLine("The byte array: ")
       Console.WriteLine("   {0}", BitConverter.ToString(bytes))
       Console.WriteLine()
       
       ' Convert the array to a base 64 string.
       Dim s As String = Convert.ToBase64String(bytes)
       Console.WriteLine("The base 64 string:{1}   {0}{1}", 
                         s, vbCrLf)
       
       ' Restore the byte array.
       Dim newBytes As Byte() = Convert.FromBase64String(s)
       Console.WriteLine("The restored byte array: ")
       Console.WriteLine("   {0}", BitConverter.ToString(newBytes))
       Console.WriteLine()
   End Sub
End Module
开发者ID:VB.NET开发者,项目名称:System,代码行数:20,代码来源:Convert.FromBase64String

输出:

The byte array:
02-04-06-08-0A-0C-0E-10-12-14

The base 64 string:
AgQGCAoMDhASFA==

The restored byte array:
02-04-06-08-0A-0C-0E-10-12-14

示例2: Example

Module Example
   Public Sub Main()
      ' Define an array of 20 elements and display it.
      Dim arr(19) As Integer 
      Dim value As Integer = 1
      For ctr As Integer = 0 To arr.GetUpperBound(0)
         arr(ctr) = value
         value = value * 2 + 1
      Next
      DisplayArray(arr)

      ' Convert the array of integers to a byte array.
      Dim bytes(arr.Length * 4 - 1) As Byte 
      For ctr As Integer = 0 To arr.Length - 1
         Array.Copy(BitConverter.GetBytes(arr(ctr)), 0, 
                    bytes, ctr * 4, 4)
      Next
         
      ' Encode the byte array using Base64 encoding
      Dim base64 As String = Convert.ToBase64String(bytes)
      Console.WriteLine("The encoded string: ")
      For ctr As Integer = 0 To base64.Length \ 50 - 1 
         Console.WriteLine(base64.Substring(ctr * 50, 
                                            If(ctr * 50 + 50 <= base64.Length, 
                                               50, base64.Length - ctr * 50)))
      Next
      Console.WriteLine()
      
      ' Convert the string back to a byte array.
      Dim newBytes() As Byte = Convert.FromBase64String(base64)

      ' Convert the byte array back to an integer array.
      Dim newArr(newBytes.Length\4 - 1) As Integer
      For ctr As Integer = 0 To newBytes.Length \ 4 - 1
         newArr(ctr) = BitConverter.ToInt32(newBytes, ctr * 4)
      Next   
      DisplayArray(newArr)
   End Sub

   Private Sub DisplayArray(arr As Array)
      Console.WriteLine("The array:")
      Console.Write("{ ")
      For ctr As Integer = 0 To arr.GetUpperBound(0) - 1
         Console.Write("{0}, ", arr.GetValue(ctr))
         If (ctr + 1) Mod 10 = 0 Then Console.Write("{0}  ", vbCrLf)
      Next
      Console.WriteLine("{0} {1}", arr.GetValue(arr.GetUpperBound(0)), "}")
      Console.WriteLine()
   End Sub
End Module
开发者ID:VB.NET开发者,项目名称:System,代码行数:50,代码来源:Convert.FromBase64String

输出:

The array:
{ 1, 3, 7, 15, 31, 63, 127, 255, 511, 1023,
2047, 4095, 8191, 16383, 32767, 65535, 131071, 262143, 524287, 1048575 }

The encoded string:
AQAAAAMAAAAHAAAADwAAAB8AAAA/AAAAfwAAAP8AAAD/AQAA/w
MAAP8HAAD/DwAA/x8AAP8/AAD/fwAA//8AAP//AQD//wMA//8H

The array:
{ 1, 3, 7, 15, 31, 63, 127, 255, 511, 1023,
2047, 4095, 8191, 16383, 32767, 65535, 131071, 262143, 524287, 1048575 }

示例3: Tester

Public Class Tester
    Public Shared Sub Main
        Dim quote As String = "AAAAA"
        Dim quoteBytes As Byte() = System.Text.Encoding.UTF8.GetBytes(quote)
        Dim quote64 As String = Convert.ToBase64String(quoteBytes)

        Dim byteSet As Byte() = Convert.FromBase64String(quote64)
        
        Dim result As String = System.Text.Encoding.UTF8.GetString(byteSet)
        
        Console.WriteLine(quote & vbNewLine & quote64 & vbNewLine & result)
    End Sub

End Class
开发者ID:VB程序员,项目名称:System,代码行数:14,代码来源:Convert.FromBase64String


注:本文中的System.Convert.FromBase64String方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。