Thanks for everyone's help. I have not tried Replace (though I may have but
I'll give it a try again) but what I ended up doing was to convert the
string to char[], loop over each character rebuilding the string and when I
found a single back slash in the char[], I added two single slashes. This
seemed to work but not very pretty. I'll try the replace suggestion.
One last question: now that I have successfully built a string of command
line paramaters that makes it to the C++ application ok and I see the
string, the C++ application only thinks there is a single command line
parameter and no more. For example, in the C# application, the command line
is:
"/file=myFile.txt /text=bold" and that string make it into the C++
application but only as a single parameter (I was hoping there would be 2).
When I copied/pasted the string into the C++
application->Properties->Debugging->Command line, I get the same thing until
I remove the quotes and then C++ sees two parameters.
So how does one build a string in C#, requiring quotes, and not have them
show up in __argv[]?
Thanks again.
Jon.
"Bruce Wood" <br*******@cana da.com> wrote in message
news:11******** **************@ z14g2000cwz.goo glegroups.com.. .
I think that I understand your problem.
You are getting a correct file name from the OpenFileDialog, and then
building an argument string for a C++ program. The contents of the
string are correct as your passing it: it contains "c:\myFile.txt" . The
problem is that the C++ application is reading the string as if it were
a command-line parameter, and is processing the \m as a special
character, not as a backslash followed by an "m".
If I am correct about this, you will want to use the .Replace()
function on the fileName parameter to fix the string so that the C++
argument parser is happy. Try something like this:
stirng argString = "/name=" + openDialog.File Name.Replace(@" \", @"\\");
This will replace all backslashes with double backslashes. See if this
helps.