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.
开发者_C百科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.
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.
Maybe it's a problem with the TextWriter?
using (StreamWriter strm = new StreamWriter(fileSts, true, Encoding.GetEncoding(1252))) {
strm.WriteLine(recno);
}
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("\"","");
精彩评论