Determines if a string consists of all valid ASCII values.

image_pdfimage_print
   
 

//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;
        }
   }
}

   
     


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