Home > database >  How to skip to specific word in a string
How to skip to specific word in a string

Time:12-15

I stored variable string1 to a Text file and "&&" then the variable string2.

File.WriteAllText(Application.StartupPath   "\\Resources\\info\\login.txt", this.username.Text   "&&"   this.password.Text);

Txt file now containing variablestring1&&variablestring2.

I need to read string from Txt file and skip to word && (read the words before and after "&&")

Can any one help me with code pls ?

i tried this but not working ..

if (File.Exists(Application.StartupPath   "\\Resources\\info\\login-info.txt"))
        {
            string[] array = File.ReadAllText(Application.StartupPath   "\\Resources\\info\\login-info.txt").Split(new string[]
            {
                "&&"
            }, StringSplitOptions.None);
            this.username.Text = array[0];
            this.password.Text = array[1];
        }

CodePudding user response:

Ideally your code should work. But this will fail if the username or password contains '&&', you will end up in more strings in the 'array' after splitting. I suggest you to keep username and password in separate lines and keep the password encrypted using any algorithms like RSA or MD5. Then you can easily read the file content and the first line will be username, and the second line will be the encrypted password. The file will look like,

admin
EncryptedPassword

CodePudding user response:

As long as your string can be read. It should have no problem.

See.

Thanks.

  •  Tags:  
  • c#
  • Related