Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. Web Development
  3. ASP.NET
  4. How to find first index value in a string is character or numeric

How to find first index value in a string is character or numeric

Scheduled Pinned Locked Moved ASP.NET
csharpdatabasetutorialquestion
4 Posts 3 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • S Offline
    S Offline
    Satish Developer
    wrote on last edited by
    #1

    Hi, how can i found that first index value in a string is char or numeric. Ex: if string is "CodeProject". I want to know first letter in a string "C" is character or numeric. can any one..give c# code for this. Ex: String str = "CodeProject";

    G. Satish

    P C 2 Replies Last reply
    0
    • S Satish Developer

      Hi, how can i found that first index value in a string is char or numeric. Ex: if string is "CodeProject". I want to know first letter in a string "C" is character or numeric. can any one..give c# code for this. Ex: String str = "CodeProject";

      G. Satish

      P Offline
      P Offline
      Petr Pechovic
      wrote on last edited by
      #2

      public static bool IsFirstCharNumber(string str) {
      if (string.IsNullOrEmpty(str))
      return false;
      int i = (int)str[0];
      return (i < 58) && (i > 47);
      }

      Petr Pechovic my latest articles: Web Page Loading in Steps - ASP.NET Solution[^] Buttons, Message Box and Confirm Box in ASP.NET 3.5[^]

      1 Reply Last reply
      0
      • S Satish Developer

        Hi, how can i found that first index value in a string is char or numeric. Ex: if string is "CodeProject". I want to know first letter in a string "C" is character or numeric. can any one..give c# code for this. Ex: String str = "CodeProject";

        G. Satish

        C Offline
        C Offline
        Covean
        wrote on last edited by
        #3

        public bool IsFirstCharDigit(string szYourstring)
        {
              if((szYourString != null) && (szYourString.Length > 0))
                    return char.IsDigit(szYourString.Chars(0));
              return false;
        }

        Greetings Covean

        C 1 Reply Last reply
        0
        • C Covean

          public bool IsFirstCharDigit(string szYourstring)
          {
                if((szYourString != null) && (szYourString.Length > 0))
                      return char.IsDigit(szYourString.Chars(0));
                return false;
          }

          Greetings Covean

          C Offline
          C Offline
          Covean
          wrote on last edited by
          #4

          Thanks for the 1 vote! So I found an error in my code. But I think 1 is too hard!

          public static bool IsFirstCharDigit(string szYourString)
          {
          if((szYourString != null) && (szYourString.Length > 0))
          return char.IsDigit(szYourString[0]);
          return false;
          }

          or

          public static bool IsFirstCharDigit(string szYourString)
          {
          if(!string.IsNullOrEmpty(szYourString))
          return char.IsDigit(szYourString[0]);
          return false;
          }

          Greetings Covean

          1 Reply Last reply
          0
          Reply
          • Reply as topic
          Log in to reply
          • Oldest to Newest
          • Newest to Oldest
          • Most Votes


          • Login

          • Don't have an account? Register

          • Login or register to search.
          • First post
            Last post
          0
          • Categories
          • Recent
          • Tags
          • Popular
          • World
          • Users
          • Groups