读取 Zürich VB.net 后出现无效字符结果
我在编写像单词“Zürich”这样的字符串时遇到问题,输出变成了“Z�rich”
我正在使用 StreamReader 和 StreamWriter。
任何人都可以帮助我解决这个问题。
代码:如下
Imports System
Imports System.IO
Imports System.Text
Module Module1
Sub Main()
Dim sReport As String
Dim strline As String
Dim objSR As StreamReader
Dim objSW As StreamWriter
sReport = "C:\InvalidChar1.txt"
Try
objSW = New StreamWriter(sReport)
objSR = New StreamReader("C:\InvalidChar.txt")
Do
strline = objSR.ReadLine
objSW.WriteLine(strline)
Loop While objSR.EndOfStream <> True
objSW.Close()
objSR.Close()
Catch e As Exception
Console.WriteLine("The process failed: {0}", e.ToString())
End Try
End Sub
End Module
I am having a problem writing a string like a word "Zürich" the output became "Z�rich"
I am using StreamReader and StreamWriter.
Anyone can help me with this.
Code: below
Imports System
Imports System.IO
Imports System.Text
Module Module1
Sub Main()
Dim sReport As String
Dim strline As String
Dim objSR As StreamReader
Dim objSW As StreamWriter
sReport = "C:\InvalidChar1.txt"
Try
objSW = New StreamWriter(sReport)
objSR = New StreamReader("C:\InvalidChar.txt")
Do
strline = objSR.ReadLine
objSW.WriteLine(strline)
Loop While objSR.EndOfStream <> True
objSW.Close()
objSR.Close()
Catch e As Exception
Console.WriteLine("The process failed: {0}", e.ToString())
End Try
End Sub
End Module
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
默认情况下,
StreamReader
和StreamWriter
都将使用 UTF-8 编码。如果这不是文件的原始编码,我预计会看到这些问题 - 确保文件是 UTF-8 文件。
By default both
StreamReader
andStreamWriter
will use the UTF-8 encoding.If this is not the original encoding of the file, I'd expect to see these issues - make sure the file is a UTF-8 file.