473,386 Members | 1,798 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,386 software developers and data experts.

question about string

hello,

I am just wondering what is the different by putting an extra "@" sign
in front of string delcaration ? Specifically :

string test = "hahaha";
string test1 = @"huhuuh";

What is the difference between test and test1 above ?

Thanks a bunch.

rgds
Rob

Nov 23 '06 #1
4 1022
Hello,

The difference is : huhuuh does not contain 'a'. :p

Try "\\" and @"\\", you'll see the difference. @ defines a verbatim
string, where escape chars have no effect.
greenrob a écrit :
hello,

I am just wondering what is the different by putting an extra "@" sign
in front of string delcaration ? Specifically :

string test = "hahaha";
string test1 = @"huhuuh";

What is the difference between test and test1 above ?

Thanks a bunch.

rgds
Rob
Nov 23 '06 #2
Hi,

greenrob wrote:
hello,

I am just wondering what is the different by putting an extra "@" sign
in front of string delcaration ? Specifically :

string test = "hahaha";
string test1 = @"huhuuh";

What is the difference between test and test1 above ?

Thanks a bunch.

rgds
Rob
When you use a '@', the string is automatically escaped.

string test = "ha\\ha\\ha";
string test1 = @"ha\ha\ha";

http://msdn2.microsoft.com/en-us/library/ms228362.aspx
(scroll down a little)

HTH,
Laurent
--
Laurent Bugnion, GalaSoft
Software engineering: http://www.galasoft-LB.ch
Private/Malaysia: http://mypage.bluewin.ch/lbugnion
Support children in Calcutta: http://www.calcutta-espoir.ch
Nov 23 '06 #3
greenrob wrote:
I am just wondering what is the different by putting an extra "@" sign
in front of string delcaration ? Specifically :

string test = "hahaha";
string test1 = @"huhuuh";

What is the difference between test and test1 above ?
Using a @ means the compiler treats the literal as a verbatim string
literal.

See http://www.pobox.com/~skeet/csharp/s....html#literals

Note that the string itself will have no idea how it was originally
declared - it's a *compile-time* feature only.

Jon

Nov 23 '06 #4
Hi Rob,

@ in front of a string has two functions. The most commonly known is that
it will treat \ as a regular character instead of an escape character,
which is handy when writing file paths

@"C:\Folder\File.txt";

instead of

"C:\\Folder\\File.txt";

It will also let you write over several lines (ignoring line breaks)

@"
Line1
Line2
";

instead of

"\r\nLine1\r\nLine2\r\n";

or

"\r\n";
+ "Line1\r\n";
+ "Line2\r\n";

Which is handy for Xml etc

On Thu, 23 Nov 2006 09:00:11 +0100, greenrob <ro*******@gmail.comwrote:
hello,

I am just wondering what is the different by putting an extra "@" sign
in front of string delcaration ? Specifically :

string test = "hahaha";
string test1 = @"huhuuh";

What is the difference between test and test1 above ?

Thanks a bunch.

rgds
Rob


--
Happy Coding!
Morten Wennevik [C# MVP]
Nov 23 '06 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: kazack | last post by:
Hi all it's me again with another question as I got further in my book. The chapter I am in covers structres, abstract data and classes. I only read through to the end of the coverage on...
16
by: dario | last post by:
Hi, Im new on phyton programming. On my GPRS modem with embedded Phyton 1.5.2+ version, I have to receive a string from serial port and after send this one enclosed in an e-mail. All OK if the...
5
by: John Baro | last post by:
I have a richtextbox which I want the "literal" rtf of. richtextbox.rtf returns {\\rtf1\\ansi\\ansicpg1252\\deff0\\deflang1033\\uc1 }\r\n\0 when i put this into a string I get...
53
by: Jeff | last post by:
In the function below, can size ever be 0 (zero)? char *clc_strdup(const char * CLC_RESTRICT s) { size_t size; char *p; clc_assert_not_null(clc_strdup, s); size = strlen(s) + 1;
15
by: DV | last post by:
I have a StringBuilder that has a string with 12,000,000 characters. When I do a ToString(), I expect to have ~25,000,000 bytes worth of memory, yet, I end up with ~43,000,000 bytes. That's...
6
by: tshad | last post by:
I am playing with Inheritance and want to make sure I understand it. I have the following Classes: ******************************************* Public Class AuthHeader:Inherits SoapHeader Public...
6
by: RSH | last post by:
I am still trying to grasp the use of real world Objects and how to conceptualize them using a business scenerio. What I have below is an outline that I am wrestling with trying to figure out a...
0
by: | last post by:
I have a question about spawning and displaying subordinate list controls within a list control. I'm also interested in feedback about the design of my search application. Lots of code is at the...
29
by: Amar Kumar Dubedy | last post by:
implement a c++ class such that it allows us to add data members at runtime.
2
by: robtyketto | last post by:
Greetings, Within my jsp I have HTML code (see below) which accepts input, one of these fields sequence unlike the others is an Integer. <FORM ACTION="wk465682AddFAQ.jsp" METHOD="POST"> Id:...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.