Contains Digit in String - CSharp System

CSharp examples for System:String Search

Description

Contains Digit in String

Demo Code


using System.Text.RegularExpressions;
using System.Text;
using System.Runtime.InteropServices;
using System.Reflection;
using System.Linq;
using System.IO;/*  ww  w.ja  v a2s .c  o m*/
using System.ComponentModel;
using System.Collections.Generic;
using System;

public class Main{
    public static bool ContainsDigit(this string s, bool nullCaseResult = false)
      {
         bool r = false;
         if (s == null)
         {
            r = nullCaseResult;
         }
         else
         {
            foreach (char c in s)
            {
               if (Char.IsDigit(c))
               {
                  r = true;
                  break;
               }
            }
         }
         return r;
      }
}

Related Tutorials