I have a dumb problem. I am reading some .cs files from disk. Performing a large number of regular expressions and other operations with them using the .net program that I did. Then write them back to disk.
The resulting files are somehow erroneously encoded. What encoding are the C # source files? And then there is the first thing in byte order, is this necessary? Does this work when I use File.WriteAllText ()?
A file-changing program is a simple .net application, and the code is just
string text = System.IO.File.ReadAllText(fn); string newText = Regex.Replace(text, regexStr, replaceStr); System.IO.File.WriteAllText(fn, newText);
There are comments in C # files, and lines don't seem to be part of the standard code page.
One of the problematic characters is "Γ€"
Decision:
it looks like it is working correctly
string text = System.IO.File.ReadAllText(fn, Encoding.GetEncoding(1252)); string newText = Regex.Replace(text, regexStr, replaceStr); System.IO.File.WriteAllText(fn, newText, Encoding.GetEncoding(1252));
source share