.net - RichTextBox 不显示 ' 并显示一个菱形,而不是里面有一个问号

标签 .net vb.net text encoding streamreader

图片显示了下面文本的显示方式:-

enter image description here

下面是更新RichTextBox的代码

If File.Exists(C_Drive + "\compu\update.txt") Then
    Dim sr As StreamReader = New StreamReader(C_Drive + "\compu\update.txt")

    ' Read and display the lines from the file until the end 
    ' of the file is reached.
    RichTextBox1.Text = RichTextBox1.Text + sr.ReadToEnd
    sr.Close()
End If

RichTextBox1.Select(0, 0)

最佳答案

这是一个关于错误编码的问题,请使用指定文本编码的StreamReader重载:

您需要确保使用正确的编码,与文本文件编码相同。

您提供的代码之后的示例:

Dim textfile As New FileInfo(String.Format("{0}\compu\update.txt", C_Drive))

If textfile.Exists() Then 
    Using sr As New StreamReader(textfile.FullName, Encoding.UTF8)
        RichTextBox1.Append(sr.ReadToEnd())
    End Using
End If

关于.net - RichTextBox 不显示 ' 并显示一个菱形,而不是里面有一个问号,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36114108/

相关文章:

mysql - MySQL 的 VB.net WHERE 语句

c# - 如何使用 C# 或 VB.Net 使键盘的 LED 闪烁

linux - Awk:删除行中最后一个空格后的文本

c - 跳转到 C 中 .txt 文件的下一行

python - 在 Python 中逐 block 读取、切片和重构数据文件

c# - 如果字符串在 .NET 中是不可变的,那么为什么 Substring 需要 O(n) 时间?

c# - 使用抽象类作为方法参数和将泛型参数限制到所述抽象类之间有什么明显的区别吗?

c# - 解码 EMV TLV 数据

c# - 使用命令在加载页面 (Xamarin.Forms) 时填充 ListView

c# - Windows、.NET 读取鼠标光标下的文本