简体   繁体   English

用':'分隔符分割1个字符串

[英]Splitting 1 string with ':' seperator

I am trying to make program that changes twitter account's password automaticly with selenium it works perfectly but my question is lets say I have 10 twitter accounts in .txt file which format is 我正在尝试制作一个可以自动使用硒自动更改Twitter帐户密码的程序,它可以正常工作,但是我的问题是可以说我在.txt文件中有10个Twitter帐户,格式为

id:password
id:password
id:password

first of all. 首先。 I want to read this txt file with c# and then separate them id(0),password(1) how can I do this? 我想用C#读取此txt文件,然后将其id(0),password(1)分开,该怎么办?

As Enigmativity mentioned in comment section you can use ReadAllLines method: 如注释部分所述,您可以使用ReadAllLines方法:

var users=  File.ReadAllLines("t.txt")
.Select(l=>new {id= l.Split(':')[0] ,password= l.Split(':')[1] })
.ToList();

Here is a quick example of how you could split it up. 这是一个简单的示例,说明如何将其拆分。 Go ahead and rework it to fit your specific requirements. 继续并对其进行重新加工以满足您的特定要求。

using (StreamReader reader = new StreamReader("file.txt"))
{
    while (true)
    {
        string line = reader.ReadLine();            

        if (line == null)
        {
            break;
        }
        else
        {
            string[] idPasswords = line.split(" ");
            for(int i = 0; i < idPasswords.length; i++)
            {
                string[] idPassword = idPasswords[i].split(":");
                string id = idPassword[0];
                string password = idPassword[1];
            }
        }
    }
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM