basic question

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Mark Fox

    #1

    basic question

    Hello,

    I've noticed in some sample code that sometimes
    people use the @ before a string when concatenating
    them. Example:

    string filePath = Appl.Request.Ph ysicalApplicati onPath +
    @"bin\" + asmname + ".dll";

    Why is this done? What is the difference between using
    the @ before the string and not using it? Thanks for
    your help!
  • Karsten Grombach

    #2
    Re: basic question

    hi mark,
    if you add the @ before a string the escape sequences are ignored. this has
    nothing to do with concatenating.
    i.e.
    @"bin\" + asmname + ".dll";
    and
    "bin\\" + asmname + ".dll";
    result in the same ..

    the 2 following statments result in : the boy said "Hello".
    @"the boy said ""Hello""."
    "the boy said \"Hello\"."

    Hope this helps
    Karsten

    "Mark Fox" <info@solelsoft ware.com> schrieb im Newsbeitrag
    news:07b201c350 e9$0e0e3500$a60 1280a@phx.gbl.. .[color=blue]
    > Hello,
    >
    > I've noticed in some sample code that sometimes
    > people use the @ before a string when concatenating
    > them. Example:
    >
    > string filePath = Appl.Request.Ph ysicalApplicati onPath +
    > @"bin\" + asmname + ".dll";
    >
    > Why is this done? What is the difference between using
    > the @ before the string and not using it? Thanks for
    > your help![/color]


    Comment

    • Yan-Hong Huang[MSFT]

      #3
      RE: basic question

      Hello Mark,

      @-quoted string literals start with @ and are enclosed in double quotation marks. For example:

      @"good morning" // a string literal

      The advantage of @-quoting is that escape sequences are not processed, which makes it easy to write, for example, a fully
      qualified file name:

      @"c:\Docs\Sourc e\a.txt" // rather than "c:\\Docs\\Sour ce\\a.txt"

      To include a double quotation mark in an @-quoted string, double it:
      @"""Ahoy!"" cried the captain." // "Ahoy!" cried the captain.

      Thanks.

      Best regards,
      Yanhong Huang
      Microsoft Online Partner Support

      Get Secure! - www.microsoft.com/security
      This posting is provided "AS IS" with no warranties, and confers no rights.

      --------------------
      !Content-Class: urn:content-classes:message
      !From: "Mark Fox" <info@solelsoft ware.com>
      !Sender: "Mark Fox" <info@solelsoft ware.com>
      !Subject: basic question
      !Date: Wed, 23 Jul 2003 00:07:18 -0700
      !Lines: 12
      !Message-ID: <07b201c350e9$0 e0e3500$a601280 a@phx.gbl>
      !MIME-Version: 1.0
      !Content-Type: text/plain;
      ! charset="iso-8859-1"
      !Content-Transfer-Encoding: 7bit
      !X-Newsreader: Microsoft CDO for Windows 2000
      !X-MimeOLE: Produced By Microsoft MimeOLE V5.50.4910.0300
      !Thread-Index: AcNQ6Q4O+P0RyAb qSfOMJUE4aJxN3A ==
      !Newsgroups: microsoft.publi c.dotnet.framew ork.aspnet
      !Path: cpmsftngxa06.ph x.gbl
      !Xref: cpmsftngxa06.ph x.gbl microsoft.publi c.dotnet.framew ork.aspnet:1612 58
      !NNTP-Posting-Host: TK2MSFTNGXA14 10.40.1.166
      !X-Tomcat-NG: microsoft.publi c.dotnet.framew ork.aspnet
      !
      !Hello,
      !
      ! I've noticed in some sample code that sometimes
      !people use the @ before a string when concatenating
      !them. Example:
      !
      !string filePath = Appl.Request.Ph ysicalApplicati onPath +
      !@"bin\" + asmname + ".dll";
      !
      !Why is this done? What is the difference between using
      !the @ before the string and not using it? Thanks for
      !your help!
      !


      Comment

      • Mark Fox

        #4
        RE: basic question

        Thank you so much for explaining this. I understand what
        it does now!
        [color=blue]
        >-----Original Message-----
        >Hello Mark,
        >
        >@-quoted string literals start with @ and are enclosed[/color]
        in double quotation marks. For example:[color=blue]
        >
        >@"good morning" // a string literal
        >
        >The advantage of @-quoting is that escape sequences are[/color]
        not processed, which makes it easy to write, for example,
        a fully[color=blue]
        >qualified file name:
        >
        >@"c:\Docs\Sour ce\a.txt" // rather[/color]
        than "c:\\Docs\\Sour ce\\a.txt"[color=blue]
        >
        >To include a double quotation mark in an @-quoted[/color]
        string, double it:[color=blue]
        >@"""Ahoy!"" cried the captain." // "Ahoy!" cried the[/color]
        captain.[color=blue]
        >
        >Thanks.
        >
        >Best regards,
        >Yanhong Huang
        >Microsoft Online Partner Support
        >
        >Get Secure! - www.microsoft.com/security
        >This posting is provided "AS IS" with no warranties, and[/color]
        confers no rights.[color=blue]
        >
        >--------------------
        >!Content-Class: urn:content-classes:message
        >!From: "Mark Fox" <info@solelsoft ware.com>
        >!Sender: "Mark Fox" <info@solelsoft ware.com>
        >!Subject: basic question
        >!Date: Wed, 23 Jul 2003 00:07:18 -0700
        >!Lines: 12
        >!Message-ID: <07b201c350e9$0 e0e3500$a601280 a@phx.gbl>
        >!MIME-Version: 1.0
        >!Content-Type: text/plain;
        >! charset="iso-8859-1"
        >!Content-Transfer-Encoding: 7bit
        >!X-Newsreader: Microsoft CDO for Windows 2000
        >!X-MimeOLE: Produced By Microsoft MimeOLE V5.50.4910.0300
        >!Thread-Index: AcNQ6Q4O+P0RyAb qSfOMJUE4aJxN3A ==
        >!Newsgroups: microsoft.publi c.dotnet.framew ork.aspnet
        >!Path: cpmsftngxa06.ph x.gbl
        >!Xref: cpmsftngxa06.ph x.gbl[/color]
        microsoft.publi c.dotnet.framew ork.aspnet:1612 58[color=blue]
        >!NNTP-Posting-Host: TK2MSFTNGXA14 10.40.1.166
        >!X-Tomcat-NG: microsoft.publi c.dotnet.framew ork.aspnet
        >!
        >!Hello,
        >!
        >! I've noticed in some sample code that sometimes
        >!people use the @ before a string when concatenating
        >!them. Example:
        >!
        >!string filePath = Appl.Request.Ph ysicalApplicati onPath[/color]
        +[color=blue]
        >!@"bin\" + asmname + ".dll";
        >!
        >!Why is this done? What is the difference between using
        >!the @ before the string and not using it? Thanks for
        >!your help!
        >!
        >
        >
        >.
        >[/color]

        Comment

        • Yan-Hong Huang[MSFT]

          #5
          RE: basic question

          Hello,

          You are welcome. :) Thanks for participating in community.

          Best regards,
          Yanhong Huang
          Microsoft Online Partner Support

          Get Secure! - www.microsoft.com/security
          This posting is provided "AS IS" with no warranties, and confers no rights.

          --------------------
          !Content-Class: urn:content-classes:message
          !From: "Mark Fox" <info@solelsoft ware.com>
          !Sender: "Mark Fox" <info@solelsoft ware.com>
          !References: <07b201c350e9$0 e0e3500$a601280 a@phx.gbl> <lbVccjPUDHA.23 44@cpmsftngxa06 .phx.gbl>
          !Subject: RE: basic question
          !Date: Wed, 23 Jul 2003 03:59:58 -0700
          !Lines: 74
          !Message-ID: <0a2101c35109$8 e7873c0$a501280 a@phx.gbl>
          !MIME-Version: 1.0
          !Content-Type: text/plain;
          ! charset="iso-8859-1"
          !Content-Transfer-Encoding: 7bit
          !X-Newsreader: Microsoft CDO for Windows 2000
          !X-MimeOLE: Produced By Microsoft MimeOLE V5.50.4910.0300
          !Thread-Index: AcNRCY54Gk5IwRK nTeGHtC7K60Mctg ==
          !Newsgroups: microsoft.publi c.dotnet.framew ork.aspnet
          !Path: cpmsftngxa06.ph x.gbl
          !Xref: cpmsftngxa06.ph x.gbl microsoft.publi c.dotnet.framew ork.aspnet:1613 13
          !NNTP-Posting-Host: TK2MSFTNGXA13 10.40.1.165
          !X-Tomcat-NG: microsoft.publi c.dotnet.framew ork.aspnet
          !
          !Thank you so much for explaining this. I understand what
          !it does now!
          !
          !>-----Original Message-----
          !>Hello Mark,
          !>
          !>@-quoted string literals start with @ and are enclosed
          !in double quotation marks. For example:
          !>
          !>@"good morning" // a string literal
          !>
          !>The advantage of @-quoting is that escape sequences are
          !not processed, which makes it easy to write, for example,
          !a fully
          !>qualified file name:
          !>
          !>@"c:\Docs\Sou rce\a.txt" // rather
          !than "c:\\Docs\\Sour ce\\a.txt"
          !>
          !>To include a double quotation mark in an @-quoted
          !string, double it:
          !>@"""Ahoy!"" cried the captain." // "Ahoy!" cried the
          !captain.
          !>
          !>Thanks.
          !>
          !>Best regards,
          !>Yanhong Huang
          !>Microsoft Online Partner Support
          !>
          !>Get Secure! - www.microsoft.com/security
          !>This posting is provided "AS IS" with no warranties, and
          !confers no rights.
          !>
          !>--------------------
          !>!Content-Class: urn:content-classes:message
          !>!From: "Mark Fox" <info@solelsoft ware.com>
          !>!Sender: "Mark Fox" <info@solelsoft ware.com>
          !>!Subject: basic question
          !>!Date: Wed, 23 Jul 2003 00:07:18 -0700
          !>!Lines: 12
          !>!Message-ID: <07b201c350e9$0 e0e3500$a601280 a@phx.gbl>
          !>!MIME-Version: 1.0
          !>!Content-Type: text/plain;
          !>! charset="iso-8859-1"
          !>!Content-Transfer-Encoding: 7bit
          !>!X-Newsreader: Microsoft CDO for Windows 2000
          !>!X-MimeOLE: Produced By Microsoft MimeOLE V5.50.4910.0300
          !>!Thread-Index: AcNQ6Q4O+P0RyAb qSfOMJUE4aJxN3A ==
          !>!Newsgroups: microsoft.publi c.dotnet.framew ork.aspnet
          !>!Path: cpmsftngxa06.ph x.gbl
          !>!Xref: cpmsftngxa06.ph x.gbl
          !microsoft.publ ic.dotnet.frame work.aspnet:161 258
          !>!NNTP-Posting-Host: TK2MSFTNGXA14 10.40.1.166
          !>!X-Tomcat-NG: microsoft.publi c.dotnet.framew ork.aspnet
          !>!
          !>!Hello,
          !>!
          !>! I've noticed in some sample code that sometimes
          !>!people use the @ before a string when concatenating
          !>!them. Example:
          !>!
          !>!string filePath = Appl.Request.Ph ysicalApplicati onPath
          !+
          !>!@"bin\" + asmname + ".dll";
          !>!
          !>!Why is this done? What is the difference between using
          !>!the @ before the string and not using it? Thanks for
          !>!your help!
          !>!
          !>
          !>
          !>.
          !>
          !


          Comment

          Working...