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. regex

regex

Scheduled Pinned Locked Moved C#
regexquestion
4 Posts 4 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.
  • A Offline
    A Offline
    angels777
    wrote on last edited by
    #1

    public bool IsInteger(string sender) { Regex regex = new Regex("[^0-9]"); return !regex.IsMatch(sender); } hi i get confused with the code above... why when i put e.g. 333 as the sender.. regex.IsMatch(sender); this is returning false ?? and i must put a ! there ?? my logic is .. when regex[^0-9] = integer then it must return true... pls advice

    N L R 3 Replies Last reply
    0
    • A angels777

      public bool IsInteger(string sender) { Regex regex = new Regex("[^0-9]"); return !regex.IsMatch(sender); } hi i get confused with the code above... why when i put e.g. 333 as the sender.. regex.IsMatch(sender); this is returning false ?? and i must put a ! there ?? my logic is .. when regex[^0-9] = integer then it must return true... pls advice

      N Offline
      N Offline
      N a v a n e e t h
      wrote on last edited by
      #2

      public bool IsInteger(string sender)
      {
      return Regex.IsMatch(sender, @"^[\d]*$", RegexOptions.None);
      }

      How about this ? BTW, easy solution is int.TryParse() than this.

      All C# applications should call Application.Quit(); in the beginning to avoid any .NET problems.- Unclyclopedia How to use google | Ask smart questions

      1 Reply Last reply
      0
      • A angels777

        public bool IsInteger(string sender) { Regex regex = new Regex("[^0-9]"); return !regex.IsMatch(sender); } hi i get confused with the code above... why when i put e.g. 333 as the sender.. regex.IsMatch(sender); this is returning false ?? and i must put a ! there ?? my logic is .. when regex[^0-9] = integer then it must return true... pls advice

        L Offline
        L Offline
        leppie
        wrote on last edited by
        #3

        angels777 wrote:

        my logic is .. when regex[^0-9] = integer then it must return true...

        Your code is wrong, the return value should not be 'notted'.

        xacc.ide - now with TabsToSpaces support
        IronScheme - 1.0 alpha 4 out now (27 May 2008)

        1 Reply Last reply
        0
        • A angels777

          public bool IsInteger(string sender) { Regex regex = new Regex("[^0-9]"); return !regex.IsMatch(sender); } hi i get confused with the code above... why when i put e.g. 333 as the sender.. regex.IsMatch(sender); this is returning false ?? and i must put a ! there ?? my logic is .. when regex[^0-9] = integer then it must return true... pls advice

          R Offline
          R Offline
          Roger Alsing 0
          wrote on last edited by
          #4

          Maybe OT, but why are you not using bool int.TryParse(string,out int) ?

          My Blog

          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