473,386 Members | 1,766 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.

Give a value with the sign \ to a string variable.

Hello!
I want to give a value with the sign \ to a string variable.
The problem is that the program always add the sign @ before the variable.
The next line gives me : @"Name\shai"

string str = "Name\\shai";

I want str to be only: "Name\shai" .
How can I do it?
Thanks in advance.
Jun 12 '06 #1
10 1726
Niron kag wrote:
Hello!
I want to give a value with the sign \ to a string variable.
The problem is that the program always add the sign @ before the variable.
The next line gives me : @"Name\shai"

string str = "Name\\shai";

I want str to be only: "Name\shai" .
How can I do it?
Thanks in advance.


The @ before the string just means it's a literal value and that '\' is
not an escape character. "Name\\shai" == @"Name\sahi"
Dan Manges
Jun 12 '06 #2
What you see is not always what you get;

If the debugger is displaying @"Name\shai" or "Name\\shai", then this *is*
the string you want; the \\ and @ are just there to tell you (as a
developer, not a user) how the string is being visualised; it doesn't change
the actual contents.

If you output the string onto the screen or a file, or whatever, then it
should appear as "Name\shai"

Marc
Jun 12 '06 #3
Hello, Niron!

Nk> string str = "Name\\shai";

the upper gives you Name\Shai,

\ - is special character, and in order to see it in the string you should escape it with another \ symbol.

You can test this with simple console application:

string str = "test1\\test2";
Console.WriteLine(str);
string str1 = "test3\\\\test4";
Console.WriteLine(str1);

--
Regards, Vadym Stetsyak
www: http://vadmyst.blogspot.com
Jun 12 '06 #4
Thanks but:
I don’t get the value I need.
If I get a variable with this value - @"name1\name2"
How can I change it to this value- "name1\name2"
(Remove the @)

I must pass the value without the @.
I try Substring but it doesn’t work.
"Vadym Stetsyak" wrote:
Hello, Niron!

Nk> string str = "Name\\shai";

the upper gives you Name\Shai,

\ - is special character, and in order to see it in the string you should escape it with another \ symbol.

You can test this with simple console application:

string str = "test1\\test2";
Console.WriteLine(str);
string str1 = "test3\\\\test4";
Console.WriteLine(str1);

--
Regards, Vadym Stetsyak
www: http://vadmyst.blogspot

Jun 12 '06 #5
Niron kag wrote:
Thanks but:
I don’t get the value I need.
If I get a variable with this value - @"name1\name2"
How can I change it to this value- "name1\name2"
(Remove the @)

I must pass the value without the @.
I try Substring but it doesn’t work.


The @ simply means that the escape characters in the string are treated as
literals. It is not actually part of the string. Just pass the string, the
@ won't get passed.
--
Tom Porterfield

Jun 12 '06 #6
You already have it:

Consider: @"name1\name2"

Look where the @ is; it isn't in the string (quotes); the string DOES NOT
contain an @ character. This is purely for the debugger and developer, so
that they know that it shouldn't be read "name1{newline}ame2" (since \n ==
{newline}). Try Console.WriteLine or Debug.WriteLine; there is no @.
Honestly.

There isn't Substring will not do anything because the @ isn't there. The
debugger is not always the easiest place to visualise string values, but
what it is saying is correct - you just have to know how to read it.

Marc

Jun 12 '06 #7
Are you actually looking at your ouput before deciding this is a bug?
"Marc Gravell" <ma**********@gmail.com> wrote in message
news:eD**************@TK2MSFTNGP05.phx.gbl...
You already have it:

Consider: @"name1\name2"

Look where the @ is; it isn't in the string (quotes); the string DOES NOT
contain an @ character. This is purely for the debugger and developer, so
that they know that it shouldn't be read "name1{newline}ame2" (since \n ==
{newline}). Try Console.WriteLine or Debug.WriteLine; there is no @.
Honestly.

There isn't Substring will not do anything because the @ isn't there. The
debugger is not always the easiest place to visualise string values, but
what it is saying is correct - you just have to know how to read it.

Marc

Jun 12 '06 #8
First, thank you for your attention!!!
Second, I am not be near the program now, but I will check it later.

"Marc Gravell" wrote:
You already have it:

Consider: @"name1\name2"

Look where the @ is; it isn't in the string (quotes); the string DOES NOT
contain an @ character. This is purely for the debugger and developer, so
that they know that it shouldn't be read "name1{newline}ame2" (since \n ==
{newline}). Try Console.WriteLine or Debug.WriteLine; there is no @.
Honestly.

There isn't Substring will not do anything because the @ isn't there. The
debugger is not always the easiest place to visualise string values, but
what it is saying is correct - you just have to know how to read it.

Marc

Jun 12 '06 #9
Niron kag <Ni******@discussions.microsoft.com> wrote:
Hello!
I want to give a value with the sign \ to a string variable.
The problem is that the program always add the sign @ before the variable.
The next line gives me : @"Name\shai"

string str = "Name\\shai";

I want str to be only: "Name\shai" .
How can I do it?
Thanks in advance.


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

--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet Blog: http://www.msmvps.com/jon.skeet
If replying to the group, please do not mail me too
Jun 12 '06 #10
Thanks every body for the attention and help.
Now it is much more clear to me!!!
"Jon Skeet [C# MVP]" wrote:
Niron kag <Ni******@discussions.microsoft.com> wrote:
Hello!
I want to give a value with the sign \ to a string variable.
The problem is that the program always add the sign @ before the variable.
The next line gives me : @"Name\shai"

string str = "Name\\shai";

I want str to be only: "Name\shai" .
How can I do it?
Thanks in advance.


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

--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet Blog: http://www.msmvps.com/jon.skeet
If replying to the group, please do not mail me too

Jun 13 '06 #11

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

Similar topics

3
by: tornado | last post by:
Hi all, I am pretty new to PHP. I was reading PHP manual and trying out the example from 2nd chapter (A simple Tutorial). When i try to print the variable as given in the example it returns...
8
by: Fred L. Kleinschmidt | last post by:
I need to know the largets value representable in a variable. However, I do not know the variable's true type - only that it is some kind of int. It may be any of the following: #typedef Newtype...
14
by: TTroy | last post by:
Hello, can anyone explain why the following function will not work for INT_MIN: /* itoa: convert n to characters in s */ void itoa(int n, char s) { int i, sign; if((sign = n) < 0) /*...
1
by: Miguel Dias Moura | last post by:
Hello, I am working in ASP.NET/VB. I have a string created by a script. How can i display the content of that string when the page is loaded so i can check its value? Thanks, Miguel
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: 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
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
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,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

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.