Encoding
-
I want to understand this code pls public GFile(string Filename) { string[] fileCtx = File.ReadAllLines(Filename, Encoding.Default); GLine gline; string[] tmpCtx; foreach (string line in fileCtx) { if (line.Contains(m_leftBracket) && line.Contains(m_rightBracket) && line != m_CRCHeader) m_Header = line; else if (line != m_CRCHeader) { tmpCtx = line.Split(new string[] { m_Equals }, StringSplitOptions.RemoveEmptyEntries); gline = new GLine(tmpCtx[0], tmpCtx[1]); if (ContainsKey(gline.Code)) this[gline.Code].CRCGiven = short.Parse(tmpCtx[1]); else Add(gline.Code, gline); } } }
-
I want to understand this code pls public GFile(string Filename) { string[] fileCtx = File.ReadAllLines(Filename, Encoding.Default); GLine gline; string[] tmpCtx; foreach (string line in fileCtx) { if (line.Contains(m_leftBracket) && line.Contains(m_rightBracket) && line != m_CRCHeader) m_Header = line; else if (line != m_CRCHeader) { tmpCtx = line.Split(new string[] { m_Equals }, StringSplitOptions.RemoveEmptyEntries); gline = new GLine(tmpCtx[0], tmpCtx[1]); if (ContainsKey(gline.Code)) this[gline.Code].CRCGiven = short.Parse(tmpCtx[1]); else Add(gline.Code, gline); } } }
This line basically means that it will read all lines in the file using the operating systems current ANSI codepage. This is a potentially dangerous encoding to use because different OS installations may use different codepages. You'd normally want to manage this by specifying a set encoding, e.g. Encoding.UTF32.
"WPF has many lovers. It's a veritable porn star!" - Josh Smith
As Braveheart once said, "You can take our freedom but you'll never take our Hobnobs!" - Martin Hughes.
-
This line basically means that it will read all lines in the file using the operating systems current ANSI codepage. This is a potentially dangerous encoding to use because different OS installations may use different codepages. You'd normally want to manage this by specifying a set encoding, e.g. Encoding.UTF32.
"WPF has many lovers. It's a veritable porn star!" - Josh Smith
As Braveheart once said, "You can take our freedom but you'll never take our Hobnobs!" - Martin Hughes.
-
You already have it. Replace Encoding.Default with Encoding.UTF8 or the like (it all depends what encoding the file was originally written out with).
"WPF has many lovers. It's a veritable porn star!" - Josh Smith
As Braveheart once said, "You can take our freedom but you'll never take our Hobnobs!" - Martin Hughes.