Gets the string up to the maximum number of characters.

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

Shortcut for string.Format.

   
 

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

using System;
using System.Collections.Generic;

namespace Redwerb.BizArk.Core.StringExt
{
    /// <summary>
    /// Provides extension methods for strings.
    /// </summary>
    public static class StringExt
    {
        /// <summary>
        /// Shortcut for string.Format.
        /// </summary>
        /// <param name="str"></param>
        /// <param name="args"></param>
        /// <returns></returns>
        public static string Format(this string str, params object[] args)
        {
            if (str == null) return null;
            return string.Format(str, args);
        }
   }
}

   
     


Truncates the string from left side

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

/// Truncates the string.
///

/// /// ///
public static string Left(this string str, int length)
{
if (str == null) return null;
if (str.Length <= length) return str; return str.Substring(0, length); } } } [/csharp]

Gets the right side of the string.

//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 right side of the string.
///

/// /// ///
public static string Right(this string str, int length)
{
if (str == null) return null;
if (str.Length <= length) return str; return str.Substring(str.Length - length); } } } [/csharp]

Determines if a string consists of all valid ASCII values.

   
 

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

using System;
using System.Collections.Generic;

namespace Redwerb.BizArk.Core.StringExt
{
    /// <summary>
    /// Provides extension methods for strings.
    /// </summary>
    public static class StringExt
    {
        /// <summary>
        /// Determines if a string consists of all valid ASCII values.
        /// </summary>
        /// <param name="str"></param>
        /// <returns></returns>
        public static bool IsAscii(this string str)
        {
            if (string.IsNullOrEmpty(str)) return true;

            foreach (var ch in str)
                if ((int)ch > 127) return false;

            return true;
        }
   }
}

   
     


Splits the string into words (all white space is removed).

   
 

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

using System;
using System.Collections.Generic;

namespace Redwerb.BizArk.Core.StringExt
{
    /// <summary>
    /// Provides extension methods for strings.
    /// </summary>
    public static class StringExt
    {
        /// <summary>
        /// Splits the string into words (all white space is removed).
        /// </summary>
        /// <param name="str"></param>
        /// <returns></returns>
        public static string[] Words(this string str)
        {
            return str.Split(new char[] { }, StringSplitOptions.RemoveEmptyEntries);
        }
   }
}

   
     


Splits the string into lines.

   
 

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

using System;
using System.Collections.Generic;

namespace Redwerb.BizArk.Core.StringExt
{
    /// <summary>
    /// Provides extension methods for strings.
    /// </summary>
    public static class StringExt
    {
        /// <summary>
        /// Splits the string into lines.
        /// </summary>
        /// <param name="str"></param>
        /// <returns></returns>
        public static string[] Lines(this string str)
        {
            var lines = new List<string>();
            using (var sr = new System.IO.StringReader(str))
            {
                string line = sr.ReadLine();
                while (line != null)
                {
                    lines.Add(line);
                    line = sr.ReadLine();
                }
            }

            return lines.ToArray();
        }
   }
}