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. Escape characters in resource strings

Escape characters in resource strings

Scheduled Pinned Locked Moved C#
comhardwarehelptutorialquestion
4 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.
  • M Offline
    M Offline
    Miszou
    wrote on last edited by
    #1

    I am trying to store strings with embedded escape characters in a resource file, for example:

    An error occurred:\r\n{0}

    However, when the string is retrieved, the escape characters are not read correctly, and I end up with a string such as this:

    An error occurred:\\r\\n{0}

    which is not terribly useful. According to this[^] article, I can call

    String.Replace( "\\r", "\r" );

    on the string, but this seems a little silly... Is this really the "standard" way of storing and managing escaped strings or am I missing something fundamental here?


    Sunrise Wallpaper Project | The StartPage Randomizer | A Random Web Page

    S 1 Reply Last reply
    0
    • M Miszou

      I am trying to store strings with embedded escape characters in a resource file, for example:

      An error occurred:\r\n{0}

      However, when the string is retrieved, the escape characters are not read correctly, and I end up with a string such as this:

      An error occurred:\\r\\n{0}

      which is not terribly useful. According to this[^] article, I can call

      String.Replace( "\\r", "\r" );

      on the string, but this seems a little silly... Is this really the "standard" way of storing and managing escaped strings or am I missing something fundamental here?


      Sunrise Wallpaper Project | The StartPage Randomizer | A Random Web Page

      S Offline
      S Offline
      simplicitylabs
      wrote on last edited by
      #2

      Is article this helpful at all? http://www.awprofessional.com/articles/article.asp?p=25322&seqNum=6&rl=1

      M 1 Reply Last reply
      0
      • S simplicitylabs

        Is article this helpful at all? http://www.awprofessional.com/articles/article.asp?p=25322&seqNum=6&rl=1

        M Offline
        M Offline
        Miszou
        wrote on last edited by
        #3

        It's not the escaping characters I'm having a problem with - it's the fact that I can't load them from a resource file without losing the fact that they're "special" characters. For example, the newline character (\n) becomes two characters, a slash and the letter 'n'. I could run String.Replace on the string to turn it back to something useful, but it shouldn't be translating my string in the first place. Besides, running String.Replace just seems like a huge hack. X| VC++ 6 could store and retrieve escaped strings from resource files with no problem, but I can't seem to get it to work as expected in Visual Studio 2005.


        Sunrise Wallpaper Project | The StartPage Randomizer | A Random Web Page

        L 1 Reply Last reply
        0
        • M Miszou

          It's not the escaping characters I'm having a problem with - it's the fact that I can't load them from a resource file without losing the fact that they're "special" characters. For example, the newline character (\n) becomes two characters, a slash and the letter 'n'. I could run String.Replace on the string to turn it back to something useful, but it shouldn't be translating my string in the first place. Besides, running String.Replace just seems like a huge hack. X| VC++ 6 could store and retrieve escaped strings from resource files with no problem, but I can't seem to get it to work as expected in Visual Studio 2005.


          Sunrise Wallpaper Project | The StartPage Randomizer | A Random Web Page

          L Offline
          L Offline
          lmoelleb
          wrote on last edited by
          #4

          It is not translating your string - it is returning it unaltered. How should it convert \n into newline when it has no idea which programming language you are loading the string from? Not all languages use \n for newline. Place a newline in the actual XML value. It should work from a technical point of view, but expect to loose it in translation (as in translate to other human languages, not escaping/unescaping). Hard coded newlines really do not belong in anything that should be translated, Make a resource for each line/paragraph instead, or calculate the newline position at runtime.

          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