Ensures the carriage returns. See http://cr.yp.to/docs/smtplf.html and 822bis section 2.3.

#region License
// Copyright (c) 2007 James Newton-King
//
// Permission is hereby granted, free of charge, to any person
// obtaining a copy of this software and associated documentation
// files (the “Software”), to deal in the Software without
// restriction, including without limitation the rights to use,
// copy, modify, merge, publish, distribute, sublicense, and/or sell
// copies of the Software, and to permit persons to whom the
// Software is furnished to do so, subject to the following
// conditions:
//
// The above copyright notice and this permission notice shall be
// included in all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND,
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
// OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
// HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
// WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
// OTHER DEALINGS IN THE SOFTWARE.
#endregion

using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Text.RegularExpressions;

namespace Newtonsoft.Utilities.Text
{
public static class StringExtensions
{

///

/// Ensures the carriage returns. See http://cr.yp.to/docs/smtplf.html and 822bis section 2.3.
///

/// The value. ///
public static string EnsureCarriageReturns(this string value)
{
return Regex.Replace(value, “(?

Truncates the specified string.

   
 

#region License
// Copyright (c) 2007 James Newton-King
//
// Permission is hereby granted, free of charge, to any person
// obtaining a copy of this software and associated documentation
// files (the "Software"), to deal in the Software without
// restriction, including without limitation the rights to use,
// copy, modify, merge, publish, distribute, sublicense, and/or sell
// copies of the Software, and to permit persons to whom the
// Software is furnished to do so, subject to the following
// conditions:
//
// The above copyright notice and this permission notice shall be
// included in all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
// OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
// HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
// WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
// OTHER DEALINGS IN THE SOFTWARE.
#endregion

using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Text.RegularExpressions;


namespace Newtonsoft.Utilities.Text
{
  public static class StringExtensions
  {


    /// <summary>
    /// Truncates the specified string.
    /// </summary>
    /// <param name="s">The string to truncate.</param>
    /// <param name="maximumLength">The maximum length of the string before it is truncated.</param>
    /// <returns></returns>
    public static string Truncate(this string s, int maximumLength)
    {
      return Truncate(s, maximumLength, "...");
    }

    /// <summary>
    /// Truncates the specified string.
    /// </summary>
    /// <param name="s">The string to truncate.</param>
    /// <param name="maximumLength">The maximum length of the string before it is truncated.</param>
    /// <param name="suffix">The suffix to place at the end of the truncated string.</param>
    /// <returns></returns>
    public static string Truncate(this string s, int maximumLength, string suffix)
    {
      if (suffix == null)
        throw new ArgumentNullException("suffix");

      if (maximumLength <= 0)
        throw new ArgumentException("Maximum length must be greater than zero.", "maximumLength");

      int subStringLength = maximumLength - suffix.Length;

      if (subStringLength <= 0)
        throw new ArgumentException("Length of suffix string is greater or equal to maximumLength");

      if (s != null &amp;&amp; s.Length > maximumLength)
      {
        string truncatedString = s.Substring(0, subStringLength);
        // incase the last character is a space
        truncatedString = truncatedString.TrimEnd();
        truncatedString += suffix;

        return truncatedString;
      }
      else
      {
        return s;
      }
    }

  }
}

   
     


Remove Html

   
 

#region License
// Copyright (c) 2007 James Newton-King
//
// Permission is hereby granted, free of charge, to any person
// obtaining a copy of this software and associated documentation
// files (the "Software"), to deal in the Software without
// restriction, including without limitation the rights to use,
// copy, modify, merge, publish, distribute, sublicense, and/or sell
// copies of the Software, and to permit persons to whom the
// Software is furnished to do so, subject to the following
// conditions:
//
// The above copyright notice and this permission notice shall be
// included in all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
// OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
// HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
// WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
// OTHER DEALINGS IN THE SOFTWARE.
#endregion

using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Text.RegularExpressions;


namespace Newtonsoft.Utilities.Text
{
  public static class StringExtensions
  {

    public static string RemoveHtml(this string s)
    {
      return RemoveHtmlInternal(s, null);
    }

    public static string RemoveHtml(this string s, IList<string> removeTags)
    {
      if (removeTags == null)
        throw new ArgumentNullException("removeTags");

      return RemoveHtmlInternal(s, removeTags);
    }

    private static string RemoveHtmlInternal(string s, IList<string> removeTags)
    {
      List<string> removeTagsUpper = null;

      if (removeTags != null)
      {
        removeTagsUpper = new List<string>(removeTags.Count);

        foreach (string tag in removeTags)
        {
          removeTagsUpper.Add(tag.ToUpperInvariant());
        }
      }

      Regex anyTag = new Regex(@"<&#91;/&#93;{0,1}s*(?<tag>w*)s*(?<attr>.*?=[&#039;""].*?[""&#039;])*?s*[/]{0,1}>", RegexOptions.Compiled);

      return anyTag.Replace(s, delegate(Match match)
      {
        string tag = match.Groups["tag"].Value.ToUpperInvariant();

        if (removeTagsUpper == null)
          return string.Empty;
        else if (removeTagsUpper.Contains(tag))
          return string.Empty;
        else
          return match.Value;
      });
    }
  }
}

   
     


Replaces the new lines in a string with the given replacement characters.

   
 

#region License
// Copyright (c) 2007 James Newton-King
//
// Permission is hereby granted, free of charge, to any person
// obtaining a copy of this software and associated documentation
// files (the "Software"), to deal in the Software without
// restriction, including without limitation the rights to use,
// copy, modify, merge, publish, distribute, sublicense, and/or sell
// copies of the Software, and to permit persons to whom the
// Software is furnished to do so, subject to the following
// conditions:
//
// The above copyright notice and this permission notice shall be
// included in all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
// OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
// HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
// WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
// OTHER DEALINGS IN THE SOFTWARE.
#endregion

using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Text.RegularExpressions;


namespace Newtonsoft.Utilities.Text
{
  public static class StringExtensions
  {

    /// <summary>
    /// Replaces the new lines in a string with the given replacement characters.
    /// </summary>
    /// <param name="s">The string to replace new lines in.</param>
    /// <param name="replacement">The replacement characters.</param>
    /// <returns></returns>
    public static string ReplaceNewLines(this string s, string replacement)
    {
      StringReader sr = new StringReader(s);
      StringBuilder sb = new StringBuilder();

      bool first = true;

      string line;
      while ((line = sr.ReadLine()) != null)
      {
        if (first)
          first = false;
        else
          sb.Append(replacement);

        sb.Append(line);
      }

      return sb.ToString();
    }
  }
}

   
     


Cut string and display three dots

   
 

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;


    public static class StringOp
    {
        public static string CutString(string OldString, int iLength)
        {
            if (OldString.Length > iLength)
            {
                OldString = OldString.Substring(0, iLength) + "...";
            }
            return OldString;
        }
    }

   
     


Convert string to sentence case

   
 

///
/// ArmyBodger 3
/// (c)2010 richyp
///
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace ArmyBodger.Core.Utilities {
    /// <summary>
    /// Some static helper methods
    /// </summary>
    public class Helpers {
        /// <summary>
        /// Convert the string e.g. fooBar to sentance case: FooBar
        /// </summary>
        /// <param name="source">The string to convert</param>
        /// <returns>The converted string</returns>
        public static string ConvertToSentenceCase(string source) {
            return source.Substring(0, 1).ToUpper() + source.Substring(1);
        }
    }
}

   
     


Get new line string

   
 

//http://www.bouncycastle.org/
//MIT X11 License

using System.IO;
using System.Text;
public class MainClass
{
    static string GetNewLine()
    {
        MemoryStream buf = new MemoryStream();
        StreamWriter w = new StreamWriter(buf, Encoding.ASCII);
        w.WriteLine();
        w.Close();
        byte[] bs = buf.ToArray();
        return Encoding.ASCII.GetString(bs, 0, bs.Length);
    }
}