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. Other Discussions
  3. IT & Infrastructure
  4. Newline "\n" - how to store and retrive on a single line in text file.

Newline "\n" - how to store and retrive on a single line in text file.

Scheduled Pinned Locked Moved IT & Infrastructure
databasehelptutorial
5 Posts 3 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.
  • S Offline
    S Offline
    Suyash
    wrote on last edited by
    #1

    Hello, Let me briefly explain the scenario before putting up my query. For internationalization purposes, we store all our strings in a text file. for some reasons we dont use the string tables. and a single string may contain one or more "\n". When I try to load a string form the text file in to CString variable, its not recognizing "\n" specified in the text file as newline character but as if "\\n" is specified. I hope the issue is clear. Your comments in this regard would be highly appreciated. Thanks in advance! Suyash

    M PJ ArendsP 2 Replies Last reply
    0
    • S Suyash

      Hello, Let me briefly explain the scenario before putting up my query. For internationalization purposes, we store all our strings in a text file. for some reasons we dont use the string tables. and a single string may contain one or more "\n". When I try to load a string form the text file in to CString variable, its not recognizing "\n" specified in the text file as newline character but as if "\\n" is specified. I hope the issue is clear. Your comments in this regard would be highly appreciated. Thanks in advance! Suyash

      M Offline
      M Offline
      Michael Dunn
      wrote on last edited by
      #2

      Are you writing the two characters backslash-n to the file? Or the byte 0A (written as '\n' in C)? If it's the first, then you're seeing exactly what you should be - the two characters backslash and n - because that's what's in the file. If you want this to be a newline in the CString, you'll need to replace backslash-n with '\n' after reading it from the file. --Mike-- Visual C++ MVP :cool: LINKS~! Ericahist | NEW!! PimpFish | CP SearchBar v3.0 | C++ Forum FAQ

      S 1 Reply Last reply
      0
      • M Michael Dunn

        Are you writing the two characters backslash-n to the file? Or the byte 0A (written as '\n' in C)? If it's the first, then you're seeing exactly what you should be - the two characters backslash and n - because that's what's in the file. If you want this to be a newline in the CString, you'll need to replace backslash-n with '\n' after reading it from the file. --Mike-- Visual C++ MVP :cool: LINKS~! Ericahist | NEW!! PimpFish | CP SearchBar v3.0 | C++ Forum FAQ

        S Offline
        S Offline
        Suyash
        wrote on last edited by
        #3

        Thanks for your suggestion Michael. As you suggested I am currently doing it as - str.Replace(CString("\\n"),CString("\n")); simillarly for \", \a,\b etc etc. Shouldn't there be any generic way to handle all the escape sequences? - Suyash

        M 1 Reply Last reply
        0
        • S Suyash

          Thanks for your suggestion Michael. As you suggested I am currently doing it as - str.Replace(CString("\\n"),CString("\n")); simillarly for \", \a,\b etc etc. Shouldn't there be any generic way to handle all the escape sequences? - Suyash

          M Offline
          M Offline
          Michael Dunn
          wrote on last edited by
          #4

          Suyash wrote:

          Shouldn't there be any generic way to handle all the escape sequences?

          You might be able to cook up a regex, but Replace() calls would be clearer IMO. --Mike-- Visual C++ MVP :cool: LINKS~! Ericahist | NEW!! PimpFish | CP SearchBar v3.0 | C++ Forum FAQ

          1 Reply Last reply
          0
          • S Suyash

            Hello, Let me briefly explain the scenario before putting up my query. For internationalization purposes, we store all our strings in a text file. for some reasons we dont use the string tables. and a single string may contain one or more "\n". When I try to load a string form the text file in to CString variable, its not recognizing "\n" specified in the text file as newline character but as if "\\n" is specified. I hope the issue is clear. Your comments in this regard would be highly appreciated. Thanks in advance! Suyash

            PJ ArendsP Offline
            PJ ArendsP Offline
            PJ Arends
            wrote on last edited by
            #5

            Lookup the FormatMessage API (or alternatively here[^] for a better solution IMHO). It uses %n for hard line breaks in a string.


            You may be right I may be crazy -- Billy Joel -- Within you lies the power for good - Use it!

            Within you lies the power for good; Use it!

            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