joins the strings with the speficied separator.

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>
        /// joins the strings with the speficied separator.
        /// </summary>
        /// <param name="separator"></param>
        /// <param name="strings"></param>
        /// <returns></returns>
        public static string Join(string separator, params string[] strings)
        {
            StringBuilder sb = new StringBuilder();
            foreach (string s in strings)
            {
                if (string.IsNullOrEmpty(s))
                    continue;

                if (sb.Length > 0)
                    sb.Append(separator);

                sb.Append(s);
            }

            return sb.ToString();
        }
   }
}

   
     


removes the specified strings in the string array from the input string

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>
        /// removes the specified strings in the string array from the input string
        /// </summary>
        /// <param name="input"></param>
        /// <param name="removals"></param>
        /// <returns></returns>
        public static string Strip(string input, params string[] removals)
        {
            string revised = input;
            foreach (string removal in removals)
            {
                int i;
                while ((i = revised.IndexOf(removal)) > -1)
                    revised = revised.Remove(i, removal.Length);
            }

            return revised;
        }
   }
}

   
     


checks if a string is null or empty or is made only of spaces

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
{
///

/// Class with handy stirng routines
///

public class StringUtil
{

///

/// checks if a string is null or empty or is made only of spaces
///

/// ///
public static bool IsWhitespace(string input)
{
if (string.IsNullOrEmpty(input))
{
return true;
}
else
{
// Check each character to see if it is whitespace or not
var isWhiteSpace = true;
for (var loop = 0; loop < input.Length; loop++) { if (!char.IsWhiteSpace(input[loop])) { isWhiteSpace = false; break; } } return isWhiteSpace; } } } } [/csharp]

returns the last word of the string, using separators space ,;!?:

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>
        /// checks if a string is null or empty or is made only of spaces 
        /// </summary>
        /// <param name="input"></param>
        /// <returns></returns>
        public static bool IsWhitespace(string input)
        {
            if (string.IsNullOrEmpty(input))
            {
                return true;
            }
            else
            {
                // Check each character to see if it is whitespace or not
                var isWhiteSpace = true;
                for (var loop = 0; loop < input.Length; loop++)
                {
                    if (!char.IsWhiteSpace(input&#91;loop&#93;))
                    {
                        isWhiteSpace = false;
                        break;
                    }
                }

                return isWhiteSpace;
            }
        }

        /// <summary>
        /// returns the last word of the string, using separators space ,;!?:
        /// </summary>
        /// <param name="input"></param>
        /// <returns></returns>
        public static string LastWord(string input)
        {
            return LastWord(input, " .,;!?:");
        }

        /// <summary>
        /// returns the last word of the string, using the specified separators 
        /// </summary>
        /// <param name="input"></param>
        /// <param name="separators"></param>
        /// <returns></returns>
        public static string LastWord(string input, string separators)
        {
            if (input == null)
                return null;

            string[] tokens = input.Split(separators.ToCharArray());
            for (int i = tokens.Length - 1; i >= 0; i--)
            {
                if (IsWhitespace(tokens[i]) == false)
                    return tokens[i].Trim();
            }

            return String.Empty;
        }
   }
}

   
     


Generates a hashcode for the string array

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>
        /// generates a hashcode for the string array
        /// </summary>
        /// <param name="values"></param>
        /// <returns></returns>
        public static int GenerateHashCode(params string[] values)
        {
            int hashcode = 0;
            foreach (string value in values)
            {
                if (value != null)
                    hashcode += value.GetHashCode();
            }
            return hashcode;
        }
   }
}

   
     


Xml Encode String

image_pdfimage_print
   
 

///////////////////////////////////////////////////////////////////////////////////////////////
//
//    This File is Part of the CallButler Open Source PBX (http://www.codeplex.com/callbutler
//
//    Copyright (c) 2005-2008, Jim Heising
//    All rights reserved.
//
//    Redistribution and use in source and binary forms, with or without modification,
//    are permitted provided that the following conditions are met:
//
//    * Redistributions of source code must retain the above copyright notice,
//      this list of conditions and the following disclaimer.
//
//    * Redistributions in binary form must reproduce the above copyright notice,
//      this list of conditions and the following disclaimer in the documentation and/or
//      other materials provided with the distribution.
//
//    * Neither the name of Jim Heising nor the names of its contributors may be
//      used to endorse or promote products derived from this software without specific prior
//      written permission.
//
//    THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
//    ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
//    WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
//    IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
//    INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
//    NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
//    PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
//    WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
//    ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
//    POSSIBILITY OF SUCH DAMAGE.
//
///////////////////////////////////////////////////////////////////////////////////////////////

using System;
using System.Collections.Generic;
using System.Text;
using System.Text.RegularExpressions;
using System.Windows.Forms;
using System.Xml;

namespace WOSI.Utilities
{
    public class StringUtils
    {
        public static string XmlEncodeString(string inputString)
        {
            XmlDocument xmlDoc = new XmlDocument();

            XmlElement xmlElement = xmlDoc.CreateElement("Str");

            xmlElement.InnerText = inputString;

            return xmlElement.InnerXml;
        }        
    }
}

   
     


Gets the string up to the maximum number of characters.

image_pdfimage_print

//Microsoft Public License (Ms-PL)
//http://visualizer.codeplex.com/license

using System;
using System.Collections.Generic;

namespace Redwerb.BizArk.Core.StringExt
{
///

/// Provides extension methods for strings.
///

public static class StringExt
{

///

/// Gets the string up to the maximum number of characters.
///

/// /// ///
public static string Max(this string str, int max)
{
return Max(str, max, false);
}

///

/// Gets the string up to the maximum number of characters. If ellipses is true and the string is longer than the max, the last 3 chars will be ellipses.
///

/// /// /// ///
public static string Max(this string str, int max, bool ellipses)
{
if (str == null) return null;

if (str.Length <= max) return str; if (ellipses) return str.Substring(0, max - 3) + "..."; else return str.Substring(0, max); } } } [/csharp]