Mega Code Archive

 
Categories / C# / Data Types
 

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