使用 .txt 文件中的信息填充文本框

Fill Textboxes With Information From .txt File

我在 .txt 文件中有此文本

Username:Password
Username2:Password2
Username3:Password3

我想将 .txt 文件中第 2 行(示例)的值设置为文本框

这就是我的意思:

Textbox1.text = Username2;
Textbox2.text = Password2;

非常感谢任何可以提供帮助的链接,在此先感谢

你可以这样做:

// Reading all lines of files
var txtLines =  File.ReadAllLines("your_file_path");

// Make sure, there should be atleast more than one line
// as you want to get username/password from second line
if(txtLines != null && txtLines.Count() > 1)
{
    // Skip first line and after that get first line 
    var secondLine = txtLines.ToList().Skip(1).First();

    // split it by colon
    var splittedText = secondLine.Split(':');
    if(splittedText.Count() > 1)
    {
        Textbox1.Text = splittedText[0];
        Textbox2.Text = splittedText[1];
    }
}