读取txt并加入richtexbox [英] Read txt and add in richtexbox
本文介绍了读取txt并加入richtexbox的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
此代码
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
My.Computer.FileSystem.CopyFile(
Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData) & "\.minecraft\logs\latest.log",
Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData) & "\.minecraft\logs\latestc.log")
Using reader As New StreamReader(Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData) & "\.minecraft\logs\latestc.log")
While Not reader.EndOfStream
Dim line As String = reader.ReadLine()
If line.Contains("Setting user: ") Then
Dim lastpart As String = line.Substring(line.LastIndexOf(": ") + 1)
FlatAlertBox3.Text = lastpart
Exit While
End If
End While
End Using
My.Computer.FileSystem.DeleteFile(
Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData) & "\.minecraft\logs\latestc.log")
End Sub
我想把这个名字http://prntscr.com/omml8w inrichtextbox1.text 喜欢上代码,但它不起作用,它只添加名字而不是所有名称,我希望所有名称都添加到 Richtextbox up 代码中,我该怎么做,请帮助我 ^_^
I want to this name http://prntscr.com/omml8w in richtextbox1.text like up code , but its not work , its add only first name not all names ,i want all names add in richtextbox up code , how can i do this plzz help me ^_^
推荐答案
如评论中所建议的,需要在文本框内容后追加lastpart
,并去掉ExitWhile
强制在第一次迭代时退出循环.
As suggested in the comments, you need to append lastpart
to the contents of the text box, and remove the Exit While
which forces exiting the loop on the first iteration.
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Dim appDataFolder = Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData)
My.Computer.FileSystem.CopyFile(
appDataFolder & "\.minecraft\logs\latest.log",
appDataFolder & "\.minecraft\logs\latestc.log")
Using reader As New StreamReader(Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData) & "\.minecraft\logs\latestc.log")
' Set text box to empty string.
FlatAlertBox3.Text = ""
While Not reader.EndOfStream
Dim line As String = reader.ReadLine()
If line.Contains("Setting user: ") Then
Dim lastpart As String = line.Substring(line.LastIndexOf(": ") + 1)
' Append to contents of text box.
FlatAlertBox3.Text += lastpart
'Exit While
End If
End While
End Using
My.Computer.FileSystem.DeleteFile(appDataFolder & "\.minecraft\logs\latestc.log")
End Sub
这篇关于读取txt并加入richtexbox的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文