Add leading and trailing double quotes to the provided string if required.

image_pdfimage_print
   
 
//CruiseControl is open source software and is developed and maintained by a group of dedicated volunteers. 
//CruiseControl is distributed under a BSD-style license.
//http://cruisecontrol.sourceforge.net/
using System;
using System.Collections;
using System.Collections.Generic;
using System.IO;
using System.Text;
using System.Text.RegularExpressions;

namespace ThoughtWorks.CruiseControl.Core.Util
{
    /// <summary>
    /// Class with handy stirng routines
    /// </summary>
    public class StringUtil
    {

        /// <summary>
        /// Add leading and trailing double quotes to the provided string if required.
        /// If the string contains a trailing backslash, that escape the added double quote,
        /// escape it also with another backslash.
        /// </summary>
        /// <param name="value">The string to double quote.</param>
        /// <returns>A double quoted string.</returns>
        public static string AutoDoubleQuoteString(string value)
        {
            if (!string.IsNullOrEmpty(value) &amp;&amp; (value.IndexOf(&#039; &#039;) > -1) &amp;&amp; (value.IndexOf(&#039;"&#039;) == -1))
            {
                if (value.EndsWith(@""))
                    value = string.Concat(value, @"");

                return string.Concat(&#039;"&#039;, value, &#039;"&#039;);
            }

            return value;
        }
   }
}

   
     


This entry was posted in Data Types. Bookmark the permalink.