tags:

views:

163

answers:

3

I have this code to write to a file, it works perfect but I have a case where a client who recorded double quote at the beginning and end of a record. I can understand that by encoding replace the accents, but I do not like me can happen.

EDIT ini.

string recno = string.empty;

recno = "123;1548;1567;10-10-01";

EDIT end.

using (FileStream fsRes = new FileStream(fileSts, FileMode.Append))
{
   using (TextWriter twRes = new StreamWriter(fsRes, Encoding.GetEncoding(1252)))
   {
      twRes.WriteLine(recno);
   }
}

Data on file:

Normal behavior:

123;1548;1567;10-10-01

On the client with the problem:

"123;1548;1567;10-10-01"


Edit: I do not know how to explain, but in the same way that the problem started, so I finish. So, sorry but do not know what happened, just hopefully not happen again.

The project I did not change, and the code is that I used as example.

Thank you all for the answers.

@Bobby, I'll see then implement the code that you put.

+2  A: 

It seems to me that this is just a case of needing to trim double quotes from either end of the string:

recno = recno.Trim('\"');

If that's not the case, please give more information. I can't see how this is really related to files or encodings.

Jon Skeet
The problem is that I have no double quotation mark in the recording into a text file. The code is that that step as an example, no changes.
andres descalzo
I'm afraid I find that hard to believe. StreamWriter doesn't magically insert quotes.
Jon Skeet
I know, for that reason that this is not happening.
andres descalzo
Sorry, I don't understand what you mean.
Jon Skeet
A: 

In case you want to replace all quotes (including the ones that might appear in the middle of the text) you could use:

string s = recno.Replace("\"","");
Marc
A: 

Maybe it's a problem with the TextWriter?

using (StreamWriter strm = new StreamWriter(fileSts, true, Encoding.GetEncoding(1252))) {
    strm.WriteLine(recno);
}
Bobby
Ok, I will try this example. Thank you.
andres descalzo