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
CODE PROJECT For Those Who Code
  • Home
  • Articles
  • FAQ
Community
  1. Home
  2. General Programming
  3. C#
  4. is there a reverse of @"abc"?

is there a reverse of @"abc"?

Scheduled Pinned Locked Moved C#
questiontutorial
7 Posts 3 Posters 1 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.
  • A Offline
    A Offline
    Ariadne
    wrote on last edited by
    #1

    Hi if I read command line args I get results of @"line\nline2" how can I convert this into "line1\nline2"? In other words: how to remove the '@'? Ariadne

    L 1 Reply Last reply
    0
    • A Ariadne

      Hi if I read command line args I get results of @"line\nline2" how can I convert this into "line1\nline2"? In other words: how to remove the '@'? Ariadne

      L Offline
      L Offline
      leppie
      wrote on last edited by
      #2

      They are the same thing, the @ only defines different escaping routines. :) xacc-ide 0.0.15 now with C#, MSIL, C, XML, ASP.NET, Nemerle, MyXaml and HLSL coloring - Screenshots

      A 1 Reply Last reply
      0
      • L leppie

        They are the same thing, the @ only defines different escaping routines. :) xacc-ide 0.0.15 now with C#, MSIL, C, XML, ASP.NET, Nemerle, MyXaml and HLSL coloring - Screenshots

        A Offline
        A Offline
        Ariadne
        wrote on last edited by
        #3

        leppie wrote: They are the same thing, the @ only defines different escaping routines. ok, but how can I change the escaping routine. if I do: sPrompt=args[i] and args[i] contains a '\' the real string of sPrompt is something like: @"...\...", but I want show this prompt in MessagBox without this '@' escape function. ie. I want show more than one line, if I get in args[i] a '\n' thanks! Ariadne

        L L 2 Replies Last reply
        0
        • A Ariadne

          leppie wrote: They are the same thing, the @ only defines different escaping routines. ok, but how can I change the escaping routine. if I do: sPrompt=args[i] and args[i] contains a '\' the real string of sPrompt is something like: @"...\...", but I want show this prompt in MessagBox without this '@' escape function. ie. I want show more than one line, if I get in args[i] a '\n' thanks! Ariadne

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

          You will need to do a str.Replace(@"\n","\n") :-> xacc-ide 0.0.15 now with C#, MSIL, C, XML, ASP.NET, Nemerle, MyXaml and HLSL coloring - Screenshots

          1 Reply Last reply
          0
          • A Ariadne

            leppie wrote: They are the same thing, the @ only defines different escaping routines. ok, but how can I change the escaping routine. if I do: sPrompt=args[i] and args[i] contains a '\' the real string of sPrompt is something like: @"...\...", but I want show this prompt in MessagBox without this '@' escape function. ie. I want show more than one line, if I get in args[i] a '\n' thanks! Ariadne

            L Offline
            L Offline
            Luis Alonso Ramos
            wrote on last edited by
            #5

            The escaping routine is for the compiler, and not for the string itself. If you do Console.WriteLine("line1\\nline2") or Console.WriteLine(@"line1\nline2"), you'll get the same output:

            line1\nline2

            In the first case, to insert a backslash in the string, you need to double it (otherwise it will be interpreted as a special character: eg. \n as newline). In the second example, the @ means that a different escaping will be performed (most special characters won't be escaped) so \n produces exactly that, \n. The @ makes a difference when specifying paths in code:

            string path1 = "C:\\Program Files\\Microsoft";
            string path2 = @"C:\Program Files\Microsoft";
            

            In memory, both path1 and path2 will contain exactly the same. If you read the string from anywhere typed by the user, you don't have to worry about escape characters. If he types one backslash, you'll get it. Escaping is only when specifying strings in code. -- LuisR


            Luis Alonso Ramos Intelectix - Chihuahua, Mexico Not much here: My CP Blog!

            The amount of sleep the average person needs is five more minutes. -- Vikram A Punathambekar, Aug. 11, 2005

            A 1 Reply Last reply
            0
            • L Luis Alonso Ramos

              The escaping routine is for the compiler, and not for the string itself. If you do Console.WriteLine("line1\\nline2") or Console.WriteLine(@"line1\nline2"), you'll get the same output:

              line1\nline2

              In the first case, to insert a backslash in the string, you need to double it (otherwise it will be interpreted as a special character: eg. \n as newline). In the second example, the @ means that a different escaping will be performed (most special characters won't be escaped) so \n produces exactly that, \n. The @ makes a difference when specifying paths in code:

              string path1 = "C:\\Program Files\\Microsoft";
              string path2 = @"C:\Program Files\Microsoft";
              

              In memory, both path1 and path2 will contain exactly the same. If you read the string from anywhere typed by the user, you don't have to worry about escape characters. If he types one backslash, you'll get it. Escaping is only when specifying strings in code. -- LuisR


              Luis Alonso Ramos Intelectix - Chihuahua, Mexico Not much here: My CP Blog!

              The amount of sleep the average person needs is five more minutes. -- Vikram A Punathambekar, Aug. 11, 2005

              A Offline
              A Offline
              Ariadne
              wrote on last edited by
              #6

              Luis Alonso Ramos wrote: The escaping routine is for the compiler, and not for the string itself. no, I think not, because I get the '@'-problem at runtime. but I'm happy leppie solved the problem with

              sPrompt=sPrompt.Replace(@"\n","\n");

              It works! :) Thanks leppie Ariadne

              L 1 Reply Last reply
              0
              • A Ariadne

                Luis Alonso Ramos wrote: The escaping routine is for the compiler, and not for the string itself. no, I think not, because I get the '@'-problem at runtime. but I'm happy leppie solved the problem with

                sPrompt=sPrompt.Replace(@"\n","\n");

                It works! :) Thanks leppie Ariadne

                L Offline
                L Offline
                Luis Alonso Ramos
                wrote on last edited by
                #7

                What that particular line of code is doing is replacing the characters \n (backslash followed by an n) with an actual newline character. It is the exact equivalent of: sPrompt = sPrompt.Replace("\\n", "\n"). Somehow you read the sPrompt string from somewhere that doesn't support escaping of characters (a resource maybe?) so you ended up with the characters '\' and 'n' in memory, instead of the actual newline (char 13) character. But the escaping only works when specifying strings by code, and it's performed by the compiler. -- LuisR


                Luis Alonso Ramos Intelectix - Chihuahua, Mexico Not much here: My CP Blog!

                The amount of sleep the average person needs is five more minutes. -- Vikram A Punathambekar, Aug. 11, 2005

                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