[英]search text file for specific value, then print the line but split into textboxes
這聽起來過於復雜,但我不太確定如何寫得更簡單,所以我會寫一個更長的版本。
在文本文件中,我保存了這種格式(用戶名、現金),並且在每一行都重復。 是否可以查找用戶名是否已存在於文件中,將本回合的現金(通過文本框輸入)添加到該特定用戶的文件中的現金中
之后,我需要在代碼中搜索用戶名的代碼,然后在單獨的文本框中輸出用戶名和現金
這是我開始的一些代碼,但到目前為止我只設法檢查用戶名是否在文件中,我無法用它做任何事情
Dim vOut As String
vOut = CStr(profit)
Dim Findstring1 = IO.File.ReadAllText("profit.txt")
Dim Lookfor As String = (Username)
If Findstring1.Contains(Username) Then
MsgBox(Findstring1)
Else
file = My.Computer.FileSystem.OpenTextFileWriter("profit.txt", True)
file.Write(vOut)
file.Write(", ")
file.Write(Username)
file.WriteLine("|")
file.Close()
End If
您可以使用File.ReadLines
和 LINQ。 要提取 UserName+Password 使用String.Split
:
Dim query = From line In File.ReadLines("profit.txt")
Where line.Contains(",")
Select arr = line.Split(","c)
Select (UserName:= arr(0).Trim(), Password:= arr(1).Trim())
For Each usernameAndPassword In query
Dim txtUserNameText = usernameAndPassword.UserName
Dim txtPasswordText = usernameAndPassword.PassWord
Next
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.