我需要阅读Config文件以获取加载设置。
我的代码:
Dim preferences As FileInfo
preferences = New FileInfo(".\settings.conf")
If preferences.Exists Then
Dim objReader As New System.IO.StreamReader(".\settings.conf")
Dim tmpLine_theme As String
Do While objReader.Peek() <> -1
tmpLine_theme = objReader.ReadLine()
If tmpLine_theme.StartsWith("theme_selected: ") Then
tmpLine_theme = tmpLine_theme.Replace("theme_selected: ", "")
theme_box.Text = tmpLine_theme
MsgBox("Theme:" + tmpLine_theme)
theme_selected_var = tmpLine_theme
Else
MsgBox("Not working")
End If
Loop
此代码会导致循环,无法继续循环。 我需要获取特定的单词,然后删除并检索所需的数据。
答案 0 :(得分:1)
如果我弄错了你,你试图得到包含特定单词的行?它并不难,只需几行代码:)
Dim readFile as New List(of String)(File.ReadAllLine("path of file"))
For each line in readFile
If line.Contains("theme_selected: ") Then
line.Replace("theme_selected: ","")
MsgBox(line)
End if
Next