473,387 Members | 3,801 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,387 software developers and data experts.

Odd string declaration

Sorry this a little bit of an odd question but I keep seeing things like
this:

string MyString
myString = @"myinitialstring"
Why the ampersand and not just,
myString = @"myinitialstring"
Nov 16 '05 #1
4 1989
Oops. I mean why not just:

myString = "myinitialstring"
"dotNEWBIE" <Newbie@dotNET> wrote in message
news:uj**************@TK2MSFTNGP12.phx.gbl...
Sorry this a little bit of an odd question but I keep seeing things like
this:

string MyString
myString = @"myinitialstring"
Why the ampersand and not just,
myString = @"myinitialstring"

Nov 16 '05 #2
Hi,

the @ is used to tell the compiler to do not parse special characters.

You can write:

str = @"c:\" instead of str = "c:\\"
or
str = @"SELECT id
FROM xxx"

instead of
str = "SELECT id" +
"FROM xxx"
Santiago Corredoira
www.syltek.com
Nov 16 '05 #3
Ahh. It negates escape characters.

Thanks.

"Santi" <no*********************@gmail.com> wrote in message
news:d1**********@nsnmpen3-gest.nuria.telefonica-data.net...
Hi,

the @ is used to tell the compiler to do not parse special characters.

You can write:

str = @"c:\" instead of str = "c:\\"
or
str = @"SELECT id
FROM xxx"

instead of
str = "SELECT id" +
"FROM xxx"
Santiago Corredoira
www.syltek.com

Nov 16 '05 #4
It doesn't negate them so much as make them unnecessary. On the other
hand, you can't use escapes to include special characters in your
string.

Very handy for DOS file paths, which are full of backslashes.

Nov 16 '05 #5

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

Similar topics

4
by: Jeff Williams | last post by:
This doesn't compile: const char** ids = { "aaa", "bbb", "ccc" }; I hope the above illustrates what I am trying to do, if it is possible, what
12
by: Riley DeWiley | last post by:
I am looking for a graceful way to declare a string const that is to be visible across many files. If I do this: //----hdr.h const char * sFoo = "foo"; //file.cpp
5
by: MLH | last post by:
I'm working with lots of long strings now, it seems. I have to import them & parse them constantly. The A97 memo field type supports only 32768 chars. What happens when this is processed... Dim...
7
by: al | last post by:
char s = "This string literal"; or char *s= "This string literal"; Both define a string literal. Both suppose to be read-only and not to be modified according to Standard. And both have...
4
by: songkv | last post by:
Hi, I am trying to reassign an array of char to a string literal by calling a function. In the function I use pointer-to-pointer since I want to reassign the "string array pointer" to the string...
12
by: Terry | last post by:
If the string object contain like below: string Mystring = " "; What function should be used for checking the "Mystring" is no char inside? Thanks Terry
24
by: v4vijayakumar | last post by:
why the following string, 'str' is read-only? char *str = "test string"; anyhow 'str' needs to be in memory. do you think, making 'str' red-only would gain performance? or, it is right?
31
by: Peter Michaux | last post by:
Hi, I want to know the name of an object's constructor function as a string. Something like this <script type="text/javascript"> function Foo(){}; var a = new Foo(); alert('"' +...
5
by: polas | last post by:
Good morning, I have a quick question to clear up some confusion in my mind. I understand that using a string literal in a declaration such as char *p = "string literal" declares a pointer to...
4
by: Chris Forone | last post by:
hello group, why have i to bracket the second ctor param in the following example? thx & hand, chris #include <fstream> #include <iterator> int main()
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: 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: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...

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.