CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 5 of 5
  1. #1
    Join Date
    May 2012
    Posts
    36

    Escape Double Quote Problem

    Hello,

    I'm having trouble figuring out how to add a single double quote in my string.

    My Code line

    Code:
    String Commandstr1 = @"C:\Temp\eventcombMT.exe" + " /file:" + "\"" + @"C:\Temp\servers.txt";
    This is what debug looks like:

    Commandstr1 "C:\\Temp\\eventcombMT.exe /file:\"C:\\Temp\\servers.txt" string

    See that it is adding the unneeded \ after file:

    My need result line:

    eventcombmt.exe /file:"C:\Temp\servers.txt";

    Can anyone see my problem with escaping this one "

    Thanks,

    Mike

  2. #2
    Join Date
    Oct 2011
    Posts
    97

    Re: Escape Double Quote Problem

    It most likely has to do with the @ symbol you're using. That symbol is used to signify that the string is already as you would like it, and to ignore escape characters. I know you're only using it in front of the strings you want to use it in front of, but it might not be possible to mix them that way. I would just do this:

    Code:
    String Commandstr1 = "C:\\Temp\\eventcombMT.exe /file:\"C:\\Temp\\servers.txt";

  3. #3
    Join Date
    May 2012
    Posts
    36

    Re: Escape Double Quote Problem

    I tryied removing the @, but it still does not like it.

    I need to have the " in the string code for the app that I'm passing it to.

    Thanks,

    Mike

  4. #4
    Join Date
    May 2012
    Posts
    9

    Re: Escape Double Quote Problem

    Quote Originally Posted by netman06 View Post
    I tryied removing the @, but it still does not like it.

    I need to have the " in the string code for the app that I'm passing it to.

    Thanks,

    Mike
    When using the @ sign you should use "" for quotes.

    i.e.

    @"eventcombmt.exe /file:""C:\Temp\servers.txt"";"

  5. #5
    Join Date
    May 2012
    Posts
    9

    Re: Escape Double Quote Problem

    Code:
    String Commandstr1 = @"C:\Temp\eventcombMT.exe /file:""C:\Temp\servers.txt""";

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured