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

    Sting with Quotes Issue

    Hello,

    I have been trying for hours to understand how to escape with double quotes and have had no luck.

    I need to pass a string to a process.start arguments line like this.

    String DF = @"C:\temp\test\backups\";

    But need to add double quotes only to the front side of this line, like this when executed:


    "C:\temp\test\backups\

    And not like this:


    "C:\temp\test\backups\"

    And cannot figure out how to do it.

    I have tried "\""

    Any help would be great thanks,

    Mike

  2. #2
    Arjay's Avatar
    Arjay is offline Moderator / EX MS MVP Power Poster
    Join Date
    Aug 2004
    Posts
    13,490

    Re: Sting with Quotes Issue

    Code:
    var df = @"C:\temp\test\backups\";            
    // var df = "\"" + @"C:\temp\test\backups\";
    
    Console.WriteLine(df);
    
    if (df[0] != '\"')
    {
        df = "\"" + df;
    }
    
    Console.WriteLine(df);
    That being said, want you probably want to do is form the complete portion of the string that needs to be double quoted and then write a method that checks and quotes the ends as necessary. This ends up being easier to follow than quoting the beginning forming the rest of the string and then quoting the end (plus the method is reusable).

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