Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C#
  4. Encoding

Encoding

Scheduled Pinned Locked Moved C#
4 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • T Offline
    T Offline
    toto_2010
    wrote on last edited by
    #1

    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); } } }

    P 1 Reply Last reply
    0
    • T toto_2010

      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); } } }

      P Offline
      P Offline
      Pete OHanlon
      wrote on last edited by
      #2

      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.

      My blog | My articles | MoXAML PowerToys | Onyx

      T 1 Reply Last reply
      0
      • P Pete OHanlon

        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.

        My blog | My articles | MoXAML PowerToys | Onyx

        T Offline
        T Offline
        toto_2010
        wrote on last edited by
        #3

        can you give me just exemple code pls ,

        P 1 Reply Last reply
        0
        • T toto_2010

          can you give me just exemple code pls ,

          P Offline
          P Offline
          Pete OHanlon
          wrote on last edited by
          #4

          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.

          My blog | My articles | MoXAML PowerToys | Onyx

          1 Reply Last reply
          0
          Reply
          • Reply as topic
          Log in to reply
          • Oldest to Newest
          • Newest to Oldest
          • Most Votes


          • Login

          • Don't have an account? Register

          • Login or register to search.
          • First post
            Last post
          0
          • Categories
          • Recent
          • Tags
          • Popular
          • World
          • Users
          • Groups