How do capture double quotes on commandline?

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

Guest

Hi,

Newbie here. Here's my code for a c# console app:

public static int Main(string[] args)
{
if (args.Length == 0)
{
Console.WriteLine("Please enter a database name.");
return 1;
}
Console.WriteLine (@args[0]);
Find t = new Find();
t.DatabaseName = @args[0];
t.Search();
return 0;
}

If I use "master" has a parameter, what gets printed to the commandline is
master. I want to print "master". Why are the double-quotes getting lost? I
also want to set the t object's DatabaseName property to include the
double-quotes, but it's losing them too.

What am I missing? Thanks.
 
Mark,

The command shell strips the quotes, as they are used to indicate
parameters that have spaces in them. You might want to try using quotes in
the quotes, like this (I'm not sure if this will work):

""master""

Hope this helps.
 
hi,

You could try using "\"Master\"". I have used this before just check if it
works for you.

Tarakeshwar
 
Thanks for the reply. ""master"" doesn't work either, the output is master.
Any other ideas?

Nicholas Paldino said:
Mark,

The command shell strips the quotes, as they are used to indicate
parameters that have spaces in them. You might want to try using quotes in
the quotes, like this (I'm not sure if this will work):

""master""

Hope this helps.


--
- Nicholas Paldino [.NET/C# MVP]
- (e-mail address removed)

mark said:
Hi,

Newbie here. Here's my code for a c# console app:

public static int Main(string[] args)
{
if (args.Length == 0)
{
Console.WriteLine("Please enter a database name.");
return 1;
}
Console.WriteLine (@args[0]);
Find t = new Find();
t.DatabaseName = @args[0];
t.Search();
return 0;
}

If I use "master" has a parameter, what gets printed to the commandline is
master. I want to print "master". Why are the double-quotes getting lost?
I
also want to set the t object's DatabaseName property to include the
double-quotes, but it's losing them too.

What am I missing? Thanks.
 
Hi mark:

You can escape the double quotes with a backslash to prevent the
command shell from interpreting them before executing your program.

\"master\"
 
Yes; you may escape the quote by prefixing it with backslash, like:
"\"master\""

--
Regards,
Dennis JD Myrén
Oslo Kodebureau
mark said:
Thanks for the reply. ""master"" doesn't work either, the output is master.
Any other ideas?

Nicholas Paldino said:
Mark,

The command shell strips the quotes, as they are used to indicate
parameters that have spaces in them. You might want to try using quotes in
the quotes, like this (I'm not sure if this will work):

""master""

Hope this helps.


--
- Nicholas Paldino [.NET/C# MVP]
- (e-mail address removed)

mark said:
Hi,

Newbie here. Here's my code for a c# console app:

public static int Main(string[] args)
{
if (args.Length == 0)
{
Console.WriteLine("Please enter a database name.");
return 1;
}
Console.WriteLine (@args[0]);
Find t = new Find();
t.DatabaseName = @args[0];
t.Search();
return 0;
}

If I use "master" has a parameter, what gets printed to the commandline is
master. I want to print "master". Why are the double-quotes getting lost?
I
also want to set the t object's DatabaseName property to include the
double-quotes, but it's losing them too.

What am I missing? Thanks.
 
Back
Top