473,800 Members | 2,640 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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 1756
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\\tes t2";
Console.WriteLi ne(str);
string str1 = "test3\\\\test4 ";
Console.WriteLi ne(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\name 2"
How can I change it to this value- "name1\name 2"
(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\\tes t2";
Console.WriteLi ne(str);
string str1 = "test3\\\\test4 ";
Console.WriteLi ne(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\name 2"
How can I change it to this value- "name1\name 2"
(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\name 2"

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.WriteLi ne 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**********@g mail.com> wrote in message
news:eD******** ******@TK2MSFTN GP05.phx.gbl...
You already have it:

Consider: @"name1\name 2"

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.WriteLi ne 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\name 2"

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.WriteLi ne 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******@discu ssions.microsof t.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.co m>
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

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

Similar topics

3
8903
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 a empty value instead of returning the browser type. Here is the line which i am using in my code and from manual: <?php echo $_SERVER; ?>
8
4698
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 short; #typedef Newtype unsigned short; #typedef Newtype int; #typedef Newtype unsigned int; #typedef Newtype long; ....etc.
14
2108
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) /* record sign */
1
1634
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
9690
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
10504
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10274
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10251
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9085
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7576
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6811
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5606
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
3764
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.