本文整理汇总了VB.NET中System.Text.UnicodeEncoding.GetPreamble方法的典型用法代码示例。如果您正苦于以下问题:VB.NET UnicodeEncoding.GetPreamble方法的具体用法?VB.NET UnicodeEncoding.GetPreamble怎么用?VB.NET UnicodeEncoding.GetPreamble使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.Text.UnicodeEncoding 的用法示例。
在下文中一共展示了UnicodeEncoding.GetPreamble方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的VB.NET代码示例。
示例1: UnicodeEncodingExample
' 导入命名空间
Imports System.Text
Class UnicodeEncodingExample
Public Shared Sub Main()
Dim byteOrderMark() As Byte
Dim b As Byte
byteOrderMark = Encoding.Unicode.GetPreamble()
Console.WriteLine("Default (little-endian) Unicode Preamble:")
For Each b In byteOrderMark
Console.Write("[{0}]", b)
Next b
Console.WriteLine(ControlChars.NewLine)
Dim bigEndianUnicode As New UnicodeEncoding(True, True)
byteOrderMark = bigEndianUnicode.GetPreamble()
Console.WriteLine("Big-endian Unicode Preamble:")
For Each b In byteOrderMark
Console.Write("[{0}]", b)
Next b
End Sub
End Class
开发者ID:VB.NET开发者,项目名称:System.Text,代码行数:24,代码来源:UnicodeEncoding.GetPreamble
示例2: Example
' 导入命名空间
Imports System.IO
Imports System.Text
Module Example
Public Sub Main()
Dim s As String = "This is a string to write to a file using UTF-16 encoding."
' Write a file using the default constructor without a BOM.
Dim enc As New UnicodeEncoding(Not BitConverter.IsLittleEndian, False)
Dim bytes() As Byte = enc.GetBytes(s)
WriteToFile("NoPreamble.txt", enc, bytes)
' Use BOM.
enc = New UnicodeEncoding(Not BitConverter.IsLittleEndian, True)
WriteToFile("Preamble.txt", enc, bytes)
End Sub
Private Sub WriteToFile(fn As String, enc As Encoding, bytes As Byte())
Dim fs As New FileStream(fn, FileMode.Create)
Dim preamble() As Byte = enc.GetPreamble()
fs.Write(preamble, 0, preamble.Length)
Console.WriteLine("Preamble has {0} bytes", preamble.Length)
fs.Write(bytes, 0, bytes.Length)
Console.WriteLine("Wrote {0} bytes to {1}.", fs.Length, fn)
fs.Close()
Console.WriteLine()
End Sub
End Module
开发者ID:VB.NET开发者,项目名称:System.Text,代码行数:29,代码来源:UnicodeEncoding.GetPreamble 输出:
Preamble has 0 bytes
Wrote 116 bytes to .\NoPreamble.txt.
Preamble has 2 bytes
Wrote 118 bytes to .\Preamble.txt.
注:本文中的System.Text.UnicodeEncoding.GetPreamble方法示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论