【发布时间】:2017-05-23 07:31:59
【问题描述】:
Public Sub openDB()
Dim Lines As New List(Of String)
Try
' Open the file using a stream reader.
Using sr As New StreamReader("Config.txt")
Dim line As String
' Read the stream to a string and write the string to the console.
line = sr.ReadLine()
Do Until String.IsNullOrEmpty(line)
Lines.Add(line)
line = sr.ReadLine
Loop
End Using
Catch e As Exception
Console.WriteLine("The file could not be read:")
Console.WriteLine(e.Message)
End Try
Dim dbname As String = g_DatabaseName
Dim server As String = Lines.Where(Function(str) str.Contains("server =")).ToString
Dim user As String = ""
Dim password As String = ""
conn = New MySqlConnection
conn.ConnectionString = String.Format("server={0}; user id={1}; password={2}; database={3}; pooling=false; Convert Zero Datetime=True", server, user, password, dbname)
conn.Open()
End Sub
我尝试从文本文件中返回一些字符串,所以我使用 StreamReader 读取文件并将它们存储到列表中。现在我尝试声明一个变量以从字符串列表中获取“localhost”,但下面的代码不适用于我。
Dim server As String = Lines.Where(Function(str) str.Contains("server =")).ToString
【问题讨论】:
-
服务器字符串给你什么回报
标签: vb.net list streamreader