string variable shows "@" symbol - why?

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

Sometimes when I view my string variables in the watch window, it shows an @ symbol preceding the value. Other times, I don't see the @ symbol. What does this mean?
 
Ok, I figured out what the @ symbol means. Now, how do I remove it? I have a string with the @ in front of it and I want to change it to a regular string. I've read this string in with the ResourceManager from a .resx file and I want to use it to format data, using \n as a new line. I can't figure out how to remove the @ symbol

I've tried copying it to another string. I've tried using the String.Format("{0}", oldString), but it always keeps the @ symbol
 
Why do you want to get rid of it? It is not part of the string. If you
notice, it is outside the quotes which means that it will never interfere
with your string operations.


Ok, I figured out what the @ symbol means. Now, how do I remove it? I
have a string with the @ in front of it and I want to change it to a regular
string. I've read this string in with the ResourceManager from a .resx file
and I want to use it to format data, using \n as a new line. I can't figure
out how to remove the @ symbol.
I've tried copying it to another string. I've tried using the
String.Format("{0}", oldString), but it always keeps the @ symbol.
 
In C#, both the following are equivalent representations of "c:\foo\bar":

string strPath = @"c:\foo\bar";
string strPath = "c:\\foo\\bar";

I believe the debugger displayed such strings the 2nd way in version 1.0 of
the framework, and people probably wondered where the extra slashes in the
string came from; so in version 1.1 they switched the display format to make
it plain that the string is to be taken literally. The fact that the @ is
outside the quotes tells you it's not part of the string.

--Bob

Ok, I figured out what the @ symbol means. Now, how do I remove it? I
have a string with the @ in front of it and I want to change it to a regular
string. I've read this string in with the ResourceManager from a .resx file
and I want to use it to format data, using \n as a new line. I can't figure
out how to remove the @ symbol.
I've tried copying it to another string. I've tried using the
String.Format("{0}", oldString), but it always keeps the @ symbol.
 
2. Be able to change from an "@" string to a non-"@" string.

Hi Bruce,

If "MyVerbatimString" is @"Hello Cruel World",

I do:

MyNewString = System.Text.RegularExpressions.Regex.Unescape(MyVerbatimString);

MyNewString should return "Hello Cruel World" WITHOUT the preceding "@".


This gave me a headache too, until I found this way around it.
Hope this helps,
Wobbles
 
Hooray! This solved it! Thanks a million.

Hi Bruce,

Glad I could help.
In fact I think that's the first time I've been of any use!
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads


Back
Top