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. General Programming
  3. C#
  4. IsDigit( ) and IsSymbol( ) function in C# [modifed]

IsDigit( ) and IsSymbol( ) function in C# [modifed]

Scheduled Pinned Locked Moved C#
csharphelp
9 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.
  • R Offline
    R Offline
    Rizwan Rathore
    wrote on last edited by
    #1

    Hi all, I want to know that are there any functions like IsDigit and IsSymbol in C# wich let us know that any particular string contains any numbers or puncuation symbols....if they exist then wich r they.....and if they dont then how can we achieve this Looking forward for help Regards, -- modified at 4:37 Saturday 20th May, 2006

    C C 2 Replies Last reply
    0
    • R Rizwan Rathore

      Hi all, I want to know that are there any functions like IsDigit and IsSymbol in C# wich let us know that any particular string contains any numbers or puncuation symbols....if they exist then wich r they.....and if they dont then how can we achieve this Looking forward for help Regards, -- modified at 4:37 Saturday 20th May, 2006

      C Offline
      C Offline
      Christian Graus
      wrote on last edited by
      #2

      Char.IsDigit, etc, work on a per char basis. I believe there are string based functions, but I have not found them as static methods on string. You can of course use int.TryParse and double.TryParse to see if the value is an int or a double, respectively. Christian Graus - Microsoft MVP - C++ -- modified at 4:47 Saturday 20th May, 2006

      1 Reply Last reply
      0
      • R Rizwan Rathore

        Hi all, I want to know that are there any functions like IsDigit and IsSymbol in C# wich let us know that any particular string contains any numbers or puncuation symbols....if they exist then wich r they.....and if they dont then how can we achieve this Looking forward for help Regards, -- modified at 4:37 Saturday 20th May, 2006

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

        Hi, I dont know about whether there is any in built function for your problem but you can implement this logic in your program by parsing the string character by character and knowing the ASCII codes for them. then compare the ascii codes for each character to be in range of for example numbers, characters or symbols. For this you will have to know the code ranges for numbers, symbols and alphabets in ASCII. And for inbuilt functions try searching the msdn or msdn online at - http://mdsn.microsoft.com/library A simple logic would be to convert the string into char[] and then loop in this array to check for Char.IsDigit and Char.IsNumber and Char.IsSymbol, etc.... (I found this after posting the message, so i modified the last post) Anant Y. Kulkarni -- modified at 4:45 Saturday 20th May, 2006

        C 1 Reply Last reply
        0
        • C coolestCoder

          Hi, I dont know about whether there is any in built function for your problem but you can implement this logic in your program by parsing the string character by character and knowing the ASCII codes for them. then compare the ascii codes for each character to be in range of for example numbers, characters or symbols. For this you will have to know the code ranges for numbers, symbols and alphabets in ASCII. And for inbuilt functions try searching the msdn or msdn online at - http://mdsn.microsoft.com/library A simple logic would be to convert the string into char[] and then loop in this array to check for Char.IsDigit and Char.IsNumber and Char.IsSymbol, etc.... (I found this after posting the message, so i modified the last post) Anant Y. Kulkarni -- modified at 4:45 Saturday 20th May, 2006

          C Offline
          C Offline
          Christian Graus
          wrote on last edited by
          #4

          You should NEVER do this. You can use foreach on a string and use Char.IsDigit ( for example ). Using ASCII codes and assuming they are valid is a bad idea on a number of levels. Christian Graus - Microsoft MVP - C++

          C R 2 Replies Last reply
          0
          • C Christian Graus

            You should NEVER do this. You can use foreach on a string and use Char.IsDigit ( for example ). Using ASCII codes and assuming they are valid is a bad idea on a number of levels. Christian Graus - Microsoft MVP - C++

            C Offline
            C Offline
            coolestCoder
            wrote on last edited by
            #5

            Hi, I havent got your point. Is there any way that the ASCII codes may be wrong? I think as you press the keys the ASCII codes are stored or sent to the program or what ever. but main point is ASCII is used for representing the characters. Means we used to do this in C. Is there any issues related to using ASCII values for comparisions. If yes, i would be greatfull to know. Also can you please elaborate on the point you replied to my post.

            Christian Graus wrote:

            Using ASCII codes and assuming they are valid is a bad idea on a number of levels.

            Number of levels? I hope you got my point. Thanks Anant Y. Kulkarni

            C 1 Reply Last reply
            0
            • C coolestCoder

              Hi, I havent got your point. Is there any way that the ASCII codes may be wrong? I think as you press the keys the ASCII codes are stored or sent to the program or what ever. but main point is ASCII is used for representing the characters. Means we used to do this in C. Is there any issues related to using ASCII values for comparisions. If yes, i would be greatfull to know. Also can you please elaborate on the point you replied to my post.

              Christian Graus wrote:

              Using ASCII codes and assuming they are valid is a bad idea on a number of levels.

              Number of levels? I hope you got my point. Thanks Anant Y. Kulkarni

              C Offline
              C Offline
              Christian Graus
              wrote on last edited by
              #6

              Anant Kulkarni wrote:

              Is there any way that the ASCII codes may be wrong?

              Well, for starters, they could be unicode codes. .NET is unicode by default.

              Anant Kulkarni wrote:

              Means we used to do this in C.

              Yep, I did it in C from time to time, although mostly I'd use the functions built in there, too.

              Anant Kulkarni wrote:

              Number of levels?

              As well as the Unicode issue, it's just a hack when the language provides stuff like Char.IsDigit. Christian Graus - Microsoft MVP - C++

              1 Reply Last reply
              0
              • C Christian Graus

                You should NEVER do this. You can use foreach on a string and use Char.IsDigit ( for example ). Using ASCII codes and assuming they are valid is a bad idea on a number of levels. Christian Graus - Microsoft MVP - C++

                R Offline
                R Offline
                Rizwan Rathore
                wrote on last edited by
                #7

                Sir i have tried to do this in this way

                foreach(char ch in docName.ToCharArray())
                {
                if(ch.IsDigit())
                break;
                }

                but the problem is that this IsDigit and other r static methods so how can i access them :( looking forward for help Regards,

                C 1 Reply Last reply
                0
                • R Rizwan Rathore

                  Sir i have tried to do this in this way

                  foreach(char ch in docName.ToCharArray())
                  {
                  if(ch.IsDigit())
                  break;
                  }

                  but the problem is that this IsDigit and other r static methods so how can i access them :( looking forward for help Regards,

                  C Offline
                  C Offline
                  Christian Graus
                  wrote on last edited by
                  #8

                  As it's a static method, you call it as I demonstrated, using the class name if (Char.IsDigit(ch)) break; Christian Graus - Microsoft MVP - C++

                  R 1 Reply Last reply
                  0
                  • C Christian Graus

                    As it's a static method, you call it as I demonstrated, using the class name if (Char.IsDigit(ch)) break; Christian Graus - Microsoft MVP - C++

                    R Offline
                    R Offline
                    Rizwan Rathore
                    wrote on last edited by
                    #9

                    Thxx Sir, its working :)

                    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