0

Good day,
I started to program c# some days ago and I´m having difficulty to read a text file.

I wrote the code below to read the following line of a text file:

AdmPassword=�‘“•—™

All caracters of the password have decimal values between 128 and 255.
The problem is . . . when I run the program, it give to me the following string:

AdmPassword=������

Someone know what I have to do to program read the file correctly?
Thankyou.

private void abrirToolStripMenuItem_Click(object sender, EventArgs e)
{
    string strAuxiliar = " ";

    /* Abre o Arquivo */
    if(openFileDialog1.ShowDialog() == DialogResult.OK)
    {
        System.IO.StreamReader LeitorDoArquivo = new 
        System.IO.StreamReader(openFileDialog1.FileName);

        /* Lê a Linha do Arquivo */
        strAuxiliar = LeitorDoArquivo.ReadLine();
    }
}
3
Contributors
3
Replies
4
Views
8 Years
Discussion Span
Last Post by hieuuk
0

I can't find any problem in that except you forgot to close it. However, when I copy your text to notepad and save it. It asks me that if I save it as ANSI it will lost data because your text isn't in ANSI. If I save it in Unicode mode. It's alright. Try it.

0

I tested it already. StreamReader is alright. Just make sure to save it as Unicode. I think when you input the data it lost already. Are u enter the information by notepad?

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.