![](/img/trans.png)
[英]Reading a binary file as text and manipulating it… [C#] Versus [VB.NET]
[英]VB.net reading ASCII code while reading a text file
我正在讀VB.net代碼中的文本文件。 我想讀這行包含一些特殊字符,其dec值為176,十六進制值為B1,符號為+和 - 在底部。 以下是顯示該值的網址:
http://www.ascii.cl/htmlcodes.htm
如何在VB.net中讀取值為176的特殊字符
這條線是這樣的
"2314 Test1 Test2 Test3 12.3 special character that has a Dec value of 176 1234"
每個單詞都由一個標簽分隔。
這是我到目前為止所做的:
reader = File.OpenText(fileInfo.FullName)
While reader.Peek <> -1
line = reader.ReadLine()
End While
reader.Close()
reader.Dispose()
我也試過這樣做:
System.Text.Encoding.GetEncoding(line)
任何幫助將不勝感激。
使用StreamReader
類的這個構造函數 (來自System.IO
命名空間):
Using reader As StreamReader = New StreamReader("C:\Users\trashr0x\Desktop\test.txt", System.Text.Encoding.Unicode)
Dim line As String = reader.ReadLine()
End Using
您還可以使用File.ReadAllText
方法(同樣,從System.IO
):
Dim testString as String = File.ReadAllText("C:\Users\trashr0x\Desktop\test.txt", System.Text.Encoding.Unicode)
我已將編碼設置為Encoding.Unicode
。 如果您不知道文件的編碼,可以嘗試其他值:
Encoding.ASCII
(正如@Jon Skeet在你的問題的評論中指出的,這個符號不是ASCII) Encoding.UTF32
Encoding.UTF8
Encoding.UTF7
Encoding.BigEndianUnicode
Encoding.Default
(默認編碼為ANSI) 另外一個有趣的讀物: “絕對最低的每個軟件開發人員絕對,必須知道關於Unicode和字符集(沒有借口!)”作者:Joel Spolsky。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.