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. String question

String question

Scheduled Pinned Locked Moved C#
question
8 Posts 5 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
    Mike Ellison
    wrote on last edited by
    #1

    What is the technical difference between defining a string this way: string s = "this is my string"; and this way? string s = @"this is my string";

    L N M N 4 Replies Last reply
    0
    • M Mike Ellison

      What is the technical difference between defining a string this way: string s = "this is my string"; and this way? string s = @"this is my string";

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

      using the @ means you don't have to escape the \ character eg. string s = "\\\\Server\\folder"; it the same as string s = @"\\Server\folder"; Grant @ Loki

      N 1 Reply Last reply
      0
      • M Mike Ellison

        What is the technical difference between defining a string this way: string s = "this is my string"; and this way? string s = @"this is my string";

        N Offline
        N Offline
        Nathan Blomquist
        wrote on last edited by
        #3

        Mike Ellison wrote: What is the technical difference between defining a string this way: string s = "this is my string"; and this way? string s = @"this is my string"; Well the first would try to escape certain characters followed by a slash string s = "this is a line \n with a newline embedded"; string s = @"this is a line \n with a slash n embedded"; The @ sign tells the compiler "this is a literal string, don't escape the characters after the slash". Hope this helps, Nathan --------------------------- Hmmm... what's a signature?

        D 1 Reply Last reply
        0
        • L Loki

          using the @ means you don't have to escape the \ character eg. string s = "\\\\Server\\folder"; it the same as string s = @"\\Server\folder"; Grant @ Loki

          N Offline
          N Offline
          Nathan Blomquist
          wrote on last edited by
          #4

          sheesh, you beat my by two minutes.... hehe... that's what I get for reading down the page first :) --------------------------- Hmmm... what's a signature?

          1 Reply Last reply
          0
          • N Nathan Blomquist

            Mike Ellison wrote: What is the technical difference between defining a string this way: string s = "this is my string"; and this way? string s = @"this is my string"; Well the first would try to escape certain characters followed by a slash string s = "this is a line \n with a newline embedded"; string s = @"this is a line \n with a slash n embedded"; The @ sign tells the compiler "this is a literal string, don't escape the characters after the slash". Hope this helps, Nathan --------------------------- Hmmm... what's a signature?

            D Offline
            D Offline
            Daniel Turini
            wrote on last edited by
            #5

            Nathan Blomquist wrote: string s = @"this is a line \n with a slash n embedded"; And also: string s = @"this is a string with two lines";


            Help me dominate the world - click this link and my army will grow

            1 Reply Last reply
            0
            • M Mike Ellison

              What is the technical difference between defining a string this way: string s = "this is my string"; and this way? string s = @"this is my string";

              M Offline
              M Offline
              Mike Ellison
              wrote on last edited by
              #6

              Thanks!

              1 Reply Last reply
              0
              • M Mike Ellison

                What is the technical difference between defining a string this way: string s = "this is my string"; and this way? string s = @"this is my string";

                N Offline
                N Offline
                Nick Parker
                wrote on last edited by
                #7

                Mike, It looks like everyone has answered you question here. I just wanted to add that strings that are defined with the "@" sign are called verbatim strings. -Nick Parker

                M 1 Reply Last reply
                0
                • N Nick Parker

                  Mike, It looks like everyone has answered you question here. I just wanted to add that strings that are defined with the "@" sign are called verbatim strings. -Nick Parker

                  M Offline
                  M Offline
                  Mike Ellison
                  wrote on last edited by
                  #8

                  Thanks, Nick. Every bit of useful information helps!

                  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