@ sign prefacing string value in debugging "watch"?

  • Thread starter Thread starter Harry Whitehouse
  • Start date Start date
H

Harry Whitehouse

For some string values, I see an @ character pre-pended to the string data
itself. IOW,

mystring=@"12345Test"

whereas othertimes I don't see the @.

What is the significance of that character in this environment?

TIA

Harry
 
It's the 'escape' :)

Ex: string path = "c://somepath.txt"; //Requires the double slash
string path = @"C://somepath.txt"; // escaped for you

Alex
 
Alex -- Didn't know that! A little research turned up:

http://msdn.microsoft.com/library/default.asp?url=/library/en-us/csref/html/vclrfString.asp

But this leads me to a problem. I have a barcode object with which I need
to encrypt a binary string. So I constructed an escaped string that is
supposed to look like this:

"\x1B\x00\x34\x89....";

I created this from a non-escaped binary representation using this function:

private string HexStringToEscapedHexString(string HexString)

{

StringBuilder EscapedString = new StringBuilder(1000,5096);


for (int counter = 0; counter < HexString.Length/2; counter++)

EscapedString.Append("\\x" + HexString.Substring(counter*2,2));


return EscapedString.ToString();

}

Somehow, when this product string appears in the debugger as it's being
loaded into the barcode object, it has the @ in front of it.

Can I get rid of the @? The barcode is literally interpreting the \x
characters in the current situation -- which is something I don't want.

TIA



Harry
 
Harry Whitehouse said:
Alex -- Didn't know that! A little research turned up:

http://msdn.microsoft.com/library/default.asp?url=/library/en-us/csre
f/html/vclrfString.asp

But this leads me to a problem. I have a barcode object with which I need
to encrypt a binary string.

"Binary string" is a contradiction in terms. If you need to encode
binary in a string, I suggest you use base64 or base16 encoding.
So I constructed an escaped string that is
supposed to look like this:

"\x1B\x00\x34\x89....";

I created this from a non-escaped binary representation using this function:

private string HexStringToEscapedHexString(string HexString)

{

StringBuilder EscapedString = new StringBuilder(1000,5096);


for (int counter = 0; counter < HexString.Length/2; counter++)

EscapedString.Append("\\x" + HexString.Substring(counter*2,2));

That's not going to work. That's going to create a string which is
literally

\x1b\x00

etc. The escaping is only done at compile time, not at runtime like
you're trying to do.
Somehow, when this product string appears in the debugger as it's being
loaded into the barcode object, it has the @ in front of it.

Can I get rid of the @? The barcode is literally interpreting the \x
characters in the current situation -- which is something I don't want.

It's not a case of "getting rid of the @" - it's a case of trying to
get the right characters to start with, which isn't done that way. If
you really want to create a string with specific Unicode characters in,
just use Append with the char itself - you can cast int to char after
parsing the hex digits.
 
Thanks to all!

My barcode vendor is going to add a method which accepts a binary byte
array. That should solve my problem!

Best

Harry
 
Back
Top