Click to See Complete Forum and Search --> : Regex building


rEnEeK
May 27th, 2009, 07:48 AM
delete please...

Alsvha
May 27th, 2009, 08:09 AM
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?

rEnEeK
May 27th, 2009, 08:12 AM
delete please...

Alsvha
May 27th, 2009, 09:23 AM
So you want the evaluated value from the Math.Ceil extracted?
Meaning you get (amongst other things) the string

<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:

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 :)

rEnEeK
May 27th, 2009, 09:30 AM
delete please...

Alsvha
May 27th, 2009, 09:35 AM
Strange - which code line of the ones I showed gives you the exception?

rEnEeK
May 27th, 2009, 09:36 AM
Dim match As System.Text.RegularExpressions.Match = regex.Match(Str)

Alsvha
May 27th, 2009, 09:40 AM
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.

rEnEeK
May 27th, 2009, 09:51 AM
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

Alsvha
May 27th, 2009, 09:54 AM
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.

rEnEeK
May 27th, 2009, 09:56 AM
delete please...

Alsvha
May 27th, 2009, 09:57 AM
Then why not just write the result string parsed from the regex into your code? Why run it through a javascript?

rEnEeK
May 27th, 2009, 10:00 AM
delete please...

Alsvha
May 27th, 2009, 10:08 AM
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:

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

rEnEeK
May 27th, 2009, 10:11 AM
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..

Alsvha
May 27th, 2009, 12:57 PM
Then I must admit that I have no idea what you're trying to accomplish and what the problem actually is. From what you've asked, I've given you all the tools needed already.

rEnEeK
May 27th, 2009, 01:07 PM
ok, so... download this video about my app

http://rapidshare.com/files/237883625/vbnet.rar