Is a char in a range : Char : Data Types C# Source Code


Custom Search

C# Source Code » Data Types » Char »

 

Is a char in a range









    

using System;
using System.Data;
using System.Text.RegularExpressions;
using System.Text;
class Class1{
        static void Main(string[] args){
            Console.WriteLine(IsInRangeCaseInsensitive('c', 'a', 'G'));
            Console.WriteLine(IsInRangeCaseInsensitive('c', 'a', 'c'));
            Console.WriteLine(IsInRangeCaseInsensitive('c', 'g', 'g'));
            Console.WriteLine(IsInRangeCaseInsensitive((char)32, 'a', 'b'));
        }
    public static bool IsInRangeCaseInsensitive(char testChar, char startOfRange, char endOfRange)
    {
      testChar = char.ToUpper(testChar);
      startOfRange = char.ToUpper(startOfRange);
      endOfRange = char.ToUpper(endOfRange);
      
      if (testChar >= startOfRange && testChar <= endOfRange)
      {
        // testChar is within the range
        return (true);
      }
      else
      {
        // testChar is NOT within the range 
        return (false);
      }
    }

}


           
       
    
   
  
   







HTML code for linking to this page:

Follow Navioo On Twitter

C# Source Code

 Navioo Data Types
» Char