Re: Get ASCII value for character when higher than 127
 
On 29 mei, 15:59, "Ben Voigt" <r...@nospam.nospam> wrote:
On the C# end, there is System.Text.Encoding.UTF8.  If you read the data
into a C# byte[], and pass it to Encoding.UTF8.GetString, you should get
back the original string.
When I read the textfile as a bytearray and use UTF8.GetString, I get
the same result as when I use a StreamReader. My code:
            foreach (string filename in
Directory.GetFiles(_config.PwdPath))
            {
                //1. read with StreamReader
                StreamReader rdr = new StreamReader(filename);
                string line = rdr.ReadToEnd();
                rdr.Close();
                line = line.Replace("\r\n", "\n");
                string xmlcontent = XOR(line, "pwdhook");
                //2. read as bytearray
                FileInfo fi = new FileInfo(filename);
                FileStream fs = fi.OpenRead();
                int nBytes = (int)fi.Length+1;
                byte[] ByteArray = new byte[nBytes];
                int nBytesRead = fs.Read(ByteArray, 0, nBytes);
                string line2 =
System.Text.Encoding.UTF8.GetString(ByteArray);
                line2 = line2.Replace("\r\n", "\n");
                string xmlcontent2 = XOR(line2, "pwdhook");
            }
Should I do something with the textfile in C++, to make sure it is
interpreted as UTF8 or something like that? Again, here's the C++ code
I use to write the password stuff to a textfile:
    fstream outPwd(path, ios::app);
    if (!outPwd)
    {
        fstream outPwd(path, ios::out );
    }
    outPwd << xmlEncrypt;
    outPwd.close();
I feel I'm getting closer to the solution with every tip I get here,
hopefully I'm there soon ;-)
Thanks again for all the help.
Sandra