Search code examples
c#splitstreamreader

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

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?


Solution

  • 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];
                }
            }
        }
    }