Click to See Complete Forum and Search --> : Inserting double-quotes into a string


brownkj
January 1st, 2005, 10:33 PM
I'm getting odd behaviour trying to insert double quotes (") into a string. According to the Help I should be able to either double enter the quotes or use the escape sequence \". Their examples are as follows:

string e = "Joe said \"Hello\" to me"; // Joe said "Hello" to me
string f = @"Joe said ""Hello"" to me"; // Joe said "Hello" to me

Instead, when I execute the following two lines and then report their values in the Command Window - Immediate I get:
string e = "Joe said \"Hello\" to me";
string f = @"Joe said ""Hello"" to me";

?e
"Joe said \"Hello\" to me"
?f
"Joe said \"Hello\" to me"

But it seems to only effect the double quote. If I try the escape for a single quote it works fine:

?"test \' end" //test and end added to make the single quote more clear
"test ' end"


Am I going crazy or is this thing not doing what its supposed to? How do I get a double-quote inserted into my string so I can execute command line apps? What I need to get to is the following to register new DLLs (represented by a FileInfo destinationFile):

System.Diagnostics.Process.Start(Environment.ExpandEnvironmentVariables("%WINDIR%") + @"\system32\regsvr32.exe /s " + destinationFile.FullName);

If the destinationFile.FullName contains spaces, this won't work without double quotes around it.

mmetzger
January 2nd, 2005, 09:38 AM
The command window (and the watchlist incidentally) display things differently, but simply creating the following:


using System;

namespace DoubleQuote_Test
{
class Class1
{
[STAThread]
static void Main(string[] args)
{
string e = "I'm quoting \"Code Guru\"";
Console.WriteLine(e);
Console.ReadLine(); // Simply so shell doesn't close immediately
}
}
}


Prints exactly as expected.

brownkj
January 3rd, 2005, 04:12 PM
Thanks for responding. I should know better than to trust what the editor tells me. Turns out the escape \" was working, and I was really running into a different error.