CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 4 of 4

Thread: @ string

  1. #1
    Join Date
    Dec 2002
    Posts
    51

    @ string

    what the result of the following strings:
    @""""
    @""","

    I think:
    ""
    ",

    Am I right?


    Thank you

  2. #2
    Join Date
    Jul 2000
    Location
    Milano, Italy
    Posts
    7,726

    Re: @ string

    yes, you got
    Code:
    "  which is codable also as string s= "\"";
    and 
    ", which si codable aslo as string s2="\",";
    ...at present time, using mainly Net 4.0, Vs 2010



    Special thanks to Lothar "the Great" Haensler, Chris Eastwood , dr_Michael, ClearCode, Iouri and
    all the other wonderful people who made and make Codeguru a great place.
    Come back soon, you Gurus.

  3. #3
    Join Date
    Dec 2002
    Posts
    51

    Re: @ string

    Cimperiali,
    so @"""" is "" or "

    Thank you for your help

  4. #4
    Join Date
    Jan 2010
    Posts
    1,133

    Re: @ string

    Normally (without using the @ symbol), when you type in ", it ends the string - so, to prevent this, you must use an escape sequence \" wherever you want " to appear as a part of the string.

    Now, @ denotes verbatim strings, which ignore escape sequences and line breaks (useful for paths, for example). However, typing " still ends the string literal, and you can't use \" anymore, so a different approach is used - whenever you need " as a part of your string, you type in "".

    So, @"""" is actually ".

    This is something you can easily test yourself; just write a simple program that prints out a string variable, and then experiment a bit.

    Code:
    // in Main()
    string test = @"""";     // change this string literal, then run again
    Console.WriteLine(test);

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured