Command line argument problem in C#

G

Guest

The following code is fairly simple to capture command line arguments:

using System;
namespace ConsoleApplication1
{
class Class1
{
static void Main(string[] args)
{
string first = args[0];
string second = args[1];
}
}
}

If the arguments are test1 and test2, it works great. If the arguments are
C:\test1 and test2, the first variable contains an "@" at the beginning of
the string. Had no trouble in visual studio 2002, but this is driving me
nuts in 2003.
 
M

Mike Edenfield

Herb said:
The following code is fairly simple to capture command line arguments:

using System;
namespace ConsoleApplication1
{
class Class1
{
static void Main(string[] args)
{
string first = args[0];
string second = args[1];
}
}
}

If the arguments are test1 and test2, it works great. If the arguments are
C:\test1 and test2, the first variable contains an "@" at the beginning of
the string. Had no trouble in visual studio 2002, but this is driving me
nuts in 2003.

The @ sign means that the string should not be escaped (that is, the
"\t" in "C:\test" isn't a tab character). The @ sign will show up in
debugging when you view the contents of the string, but it should be
*outside* of the string data itself: @"C:\Test1". It shouldn't appear
anywhere when the string is displayed in a control...

--Mike
 
G

Guest

Enlightenment ensues.. all is clear.

Is there a link that documents this feature?

Thank you Mike,

Herb

Mike Edenfield said:
Herb said:
The following code is fairly simple to capture command line arguments:

using System;
namespace ConsoleApplication1
{
class Class1
{
static void Main(string[] args)
{
string first = args[0];
string second = args[1];
}
}
}

If the arguments are test1 and test2, it works great. If the arguments are
C:\test1 and test2, the first variable contains an "@" at the beginning of
the string. Had no trouble in visual studio 2002, but this is driving me
nuts in 2003.

The @ sign means that the string should not be escaped (that is, the
"\t" in "C:\test" isn't a tab character). The @ sign will show up in
debugging when you view the contents of the string, but it should be
*outside* of the string data itself: @"C:\Test1". It shouldn't appear
anywhere when the string is displayed in a control...

--Mike
 
M

Mike Edenfield

Herb said:
Enlightenment ensues.. all is clear.

Is there a link that documents this feature?

It's in the C# language specification. This is part of the .NET help
system, look up "string literals" and make sure Visual C# is part of
your help filter. This is a feature of C#, not of .NET in general, in
case that wasn't clear already :)

(To be honest, I only knew this existed because I read it in a book...
unless you're an avid reader of extensive language specs, I dunno that
you would normally run across this.)

In the C# Language Specification, you see:

----------
2.4.4.5 String literals

A verbatim string literal consists of an @ character followed by a
double-quote character, zero or more characters, and a closing
double-quote character. A simple example is @"hello". In a verbatim
string literal, the characters between the delimiters are interpreted
verbatim, the only exception being a quote-escape-sequence. In
particular, simple escape sequences and hexadecimal and Unicode escape
sequences are not processed in verbatim string literals. A verbatim
string literal may span multiple lines.
----------
 

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

Top