CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Page 1 of 2 12 LastLast
Results 1 to 15 of 17

Thread: Regex building

  1. #1
    Join Date
    May 2009
    Posts
    9

    Regex building

    delete please...
    Last edited by rEnEeK; May 30th, 2009 at 12:22 PM.

  2. #2
    Join Date
    Feb 2005
    Location
    Denmark
    Posts
    742

    Re: Regex building

    Well - what specifically are you interested in from the string? And does the response you want to parse always look that way?

    Is it only the content of the Math.Ceil you want?

  3. #3
    Join Date
    May 2009
    Posts
    9

    Re: Regex building

    delete please...
    Last edited by rEnEeK; May 30th, 2009 at 12:23 PM.

  4. #4
    Join Date
    Feb 2005
    Location
    Denmark
    Posts
    742

    Re: Regex building

    So you want the evaluated value from the Math.Ceil extracted?
    Meaning you get (amongst other things) the string
    Code:
    <td>Traffic left:</td><td align=right><b><script>document.write(setzeTT(""+Math.ceil(24686696/1000)));</script> MB</b></td>
    into your code, you want to pass it through a regex and display it?

    Then I'd think something like this would be enough:
    Code:
    Dim regex As New System.Text.RegularExpressions.Regex("Math.ceil\((?<numerator>\d+)/(?<denominator>\d+)[^>]+>(?<unit>[^<]+)")
    Dim match As System.Text.RegularExpressions.Match = regex.Match(str)
    Dim result As String = Math.Ceiling(CInt(match.Groups("numerator").Value) / CInt(match.Groups("denominator").Value)) & match.Groups("unit").Value
    This will for the above string, provide the result "24687 MB"
    (remember to check for IsMatch or whether groups exists etc before trying to convert the values to integer)

    Hope this helps, otherwise I've misunderstood what you wanted

  5. #5
    Join Date
    May 2009
    Posts
    9

    Re: Regex building

    delete please...
    Last edited by rEnEeK; May 30th, 2009 at 12:23 PM.

  6. #6
    Join Date
    Feb 2005
    Location
    Denmark
    Posts
    742

    Re: Regex building

    Strange - which code line of the ones I showed gives you the exception?

  7. #7
    Join Date
    May 2009
    Posts
    9

    Re: Regex building

    Dim match As System.Text.RegularExpressions.Match = regex.Match(Str)

  8. #8
    Join Date
    Feb 2005
    Location
    Denmark
    Posts
    742

    Re: Regex building

    str is the string you want to parse, so it must be replaced with the content you want to match on.
    I think you called it responsedata earlier.

  9. #9
    Join Date
    May 2009
    Posts
    9

    Re: Regex building

    Thanks very much, now it works... One question again...

    <script>document.write(setzeTT("315926"))</script> MB</b>

    How can I write this?

    315926 is generated number from webpage

  10. #10
    Join Date
    Feb 2005
    Location
    Denmark
    Posts
    742

    Re: Regex building

    Quote Originally Posted by rEnEeK View Post
    Thanks very much, now it works... One question again...

    <script>document.write(setzeTT("315926"))</script> MB</b>

    How can I write this?
    Where, from where (and why) do you want to write it?
    I'm not sure I understand the issue.

    If you need to call a javascript function with that value, numerous techniques exists from using the ScriptManager, to simply a label/span or ...... but as said - I'm not sure I understand the issue.

  11. #11
    Join Date
    May 2009
    Posts
    9

    Re: Regex building

    delete please...
    Last edited by rEnEeK; May 30th, 2009 at 12:23 PM.

  12. #12
    Join Date
    Feb 2005
    Location
    Denmark
    Posts
    742

    Re: Regex building

    Then why not just write the result string parsed from the regex into your code? Why run it through a javascript?

  13. #13
    Join Date
    May 2009
    Posts
    9

    Re: Regex building

    delete please...
    Last edited by rEnEeK; May 30th, 2009 at 12:23 PM.

  14. #14
    Join Date
    Feb 2005
    Location
    Denmark
    Posts
    742

    Re: Regex building

    Well - that code is also just wrong from what I can see. You're not putting any content into the strbstorage stringbuilder and you don't seem to use the match collection.

    I think you need to take it one step at the time, because either you're trying to tackle multiple things at once and not understanding the code or similar.

    You have the response string which you wanted to parse through a regular expression to show traffic remaining:
    Code:
    <td>Traffic left:</td><td align=right><b><script>document.write(setzeTT(""+Math.ceil(24686696/1000)));</script> MB</b></td>
    If you run that through the code I gave you, you'll have a string which contains "24687 MB" (I named it result in the example).

    Why then not just assign that result value to your label - for example like: lblStorage.Text = result

    I am really starting to not understand what you're trying to accomplish because as said - it seems like multiple different things going on and it doesn't look like you're using the code snippets I provided.

  15. #15
    Join Date
    May 2009
    Posts
    9

    Re: Regex building

    I tried all, but I still don't know, how can I write it... I used google, some books, but it still doesn't work..

Page 1 of 2 12 LastLast

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured