如何把汉字读取到textbox.text里面去啊?上图和真相...
vb.net吧
全部回复
仅看楼主
level 5
如下:Dim path As String = ""
Dim fimout As New OpenFileDialog
fimout.Title = "打开文本文件"
fimout.Filter = "文本文件(*.txt)|*.txt"
If fimout.ShowDialog = Windows.Forms.DialogResult.OK Then
path = fimout.FileName
Else
Exit Sub
End If
Dim readtxt As New StreamReader(path, System.Text.Encoding.UTF8)
TextBox1.Text = readtxt.ReadToEnd
readtxt.Close()
但是读取的汉字是乱码,英文的还好,如图,
求指点一二,VB.NET的论坛少,求助不易啊...
2012年12月04日 11点12分 1
level 9
Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
Dim sw As System.IO.StreamWriter '写入
sw = New System.IO.StreamWriter(Application.StartupPath + "1.txt", False)
sw.WriteLine(TextBox1.Text)
sw.Close()
End Sub Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button3.Click
Dim sr As System.IO.StreamReader '读取
sr = New System.IO.StreamReader(Application.StartupPath + "1.txt", False)
TextBox1.Text = sr.ReadLine
sr.Close()
End Sub
自己改一下
2012年12月04日 13点12分 2
level 5
感谢,不过实际我改了一下试了下,我的还是不能显示汉字,我的代码如下: Private Sub Button5_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button5.Click
Dim sr As System.IO.StreamReader '读取
sr = New System.IO.StreamReader("c:\1.txt")
TextBox1.Text = sr.ReadToEnd
sr.Close()
End Sub
还是向上图所示乱码呢,,,哎,真不知道是怎么回事,,,
2012年12月05日 13点12分 3
level 9
Dim sr As System.IO.StreamReader '读取
sr = New System.IO.StreamReader("c:\1.txt", System.Text.Encoding.GetEncoding("GB2312"))
TextBox1.Text = sr.ReadToEnd
sr.Close()
好像是编码问题 你试试看看能不能解决
2012年12月05日 15点12分 5
level 12

编码问题 gb2312
2012年12月06日 01点12分 6
level 10
回复 楼主 my.computr.filesystem.readalltext() 这个很好用,如果你只是把txt读入textbox的话,用这个很简单,也没乱码。保存的时候是read换成 write
2012年12月06日 03点12分 7
level 5
,就是编码问题,谢谢各位,解决后如下:
Private Sub 打开OToolStripButton_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles 打开OToolStripButton.Click
Dim path As String
Dim readtxt As StreamReader
Dim formout As New OpenFileDialog
formout.Filter = "文本文件 (*.txt)|*.txt|所有文件 (*.*)|*.*"
formout.Title = "测试 打开文本文件"
If formout.ShowDialog = DialogResult.OK Then
path = formout.FileName
Else
Exit Sub
End If
readtxt = New StreamReader(path, System.Text.Encoding.GetEncoding("GB2312"))
TextBox1.Text = readtxt.ReadToEnd
readtxt.Close()
End Sub

2012年12月06日 12点12分 8
level 3
FileIO.FileSystem.ReadAllText(文件地址, System.Text.Encoding.Default)
2013年02月05日 02点02分 10
level 13
记事本默认使用ansi编码,这种编码在汉子部分和gb那个一样。ansi用getencoding("0")
2013年02月06日 00点02分 11
1