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. Extract numbers with % sign from a string

Extract numbers with % sign from a string

Scheduled Pinned Locked Moved ASP.NET
tutorial
5 Posts 2 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.
  • B Offline
    B Offline
    byka
    wrote on last edited by
    #1

    I need to Extract numbers with % sign from a string. Example: "50%", "test 100%","ttest 50% test test". thank you

    Richard DeemingR 1 Reply Last reply
    0
    • B byka

      I need to Extract numbers with % sign from a string. Example: "50%", "test 100%","ttest 50% test test". thank you

      Richard DeemingR Offline
      Richard DeemingR Offline
      Richard Deeming
      wrote on last edited by
      #2

      Use a Regular Expression[^]. For example:

      \d+%


      "These people looked deep within my soul and assigned me a number based on the order in which I joined." - Homer

      "These people looked deep within my soul and assigned me a number based on the order in which I joined" - Homer

      B 1 Reply Last reply
      0
      • Richard DeemingR Richard Deeming

        Use a Regular Expression[^]. For example:

        \d+%


        "These people looked deep within my soul and assigned me a number based on the order in which I joined." - Homer

        B Offline
        B Offline
        byka
        wrote on last edited by
        #3

        what am I doing incorrect: Dim number = Regex.Match("50%", "\d+$").Value number is empty

        Richard DeemingR 1 Reply Last reply
        0
        • B byka

          what am I doing incorrect: Dim number = Regex.Match("50%", "\d+$").Value number is empty

          Richard DeemingR Offline
          Richard DeemingR Offline
          Richard Deeming
          wrote on last edited by
          #4

          You're using the "end-of-line" anchor ($), but the number is not at the end of the line. You want to match the literal % character instead.

          Dim number As String = Regex.Match("50%", "\d+%").Value


          "These people looked deep within my soul and assigned me a number based on the order in which I joined." - Homer

          "These people looked deep within my soul and assigned me a number based on the order in which I joined" - Homer

          B 1 Reply Last reply
          0
          • Richard DeemingR Richard Deeming

            You're using the "end-of-line" anchor ($), but the number is not at the end of the line. You want to match the literal % character instead.

            Dim number As String = Regex.Match("50%", "\d+%").Value


            "These people looked deep within my soul and assigned me a number based on the order in which I joined." - Homer

            B Offline
            B Offline
            byka
            wrote on last edited by
            #5

            got it. thank you

            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