Finding a string within html webpage

Posts 110 of 10 · Page 1 of 1
Finding a string within html webpage
Titles is a bit off, but I need help splitting, trimming, whatever you're suppose to do to get this string out of a block of text.I'm terrible at thisTo the problem, I need help finding this, XX_X_X.txt (X's meaning numbers, which I'm trying to look for)I'm trying to get it from a webpage html source, which that part I can do.Any help is appreciative

Source:
Source.txt5 KB · 9 downloads Scanning…
Dim result As Regex = New Regex("strFileName=(?<swf>game\d+(_\d+){2}.swf)")
Dim match As Match = result.Match(pageSource)
Dim swfFileName As String = match.Groups("swf")
Quote Originally Posted by master131 View Post
Dim result As Regex = New Regex("strFileName=(?<swf>game\d+(_\d+){2}.swf)")
Dim match As Match = result.Match(pageSource)
Dim swfFileName As String = match.Groups("swf")
What the last line does? Thats the only problem I have with that code
Well, I wasn't sure if that line would work in VB.NET, try this instread:
Dim swfFileName As String = match.Groups(1).Value
Quote Originally Posted by master131 View Post
Well, I wasn't sure if that line would work in VB.NET, try this instread:
Dim swfFileName As String = match.Groups(1).Value
Didn't quite give me what I've wanted, but I got the result I needed. You helped me a lot

Code:
Cation, Its very bootlegged
 Dim x As String = GetBuild()
        Dim result As Regex = New Regex("strFileName=(?<swf>game\d+(_\d+){2}.swf)")
        Dim match As Match = result.Match(x)
        Dim y() As String = match.ToString.Split(".")
        Dim l As String = y(1).Trim(".")
        textbox.Text = y(0).Remove(0, 16).Replace("_", ".")
I likes your drawings btw
Fan of your coding works
Close pls
Also, here's what you wanted but with less code.
Code:
Dim groups As GroupCollection = Regex.Match(x, "strFileName=game(?<major>\d+)_(?<minor>\d+)_(?<revision>\d+).swf").Groups
Dim version As String = String.Format("{0}.{1}.{2}", groups(1), groups(2), groups(3))
Quote Originally Posted by master131 View Post
Also, here's what you wanted but with less code.
Code:
Dim groups As GroupCollection = Regex.Match(x, "strFileName=game(?<major>\d+)_(?<minor>\d+)_(?<revision>\d+).swf").Groups
Dim version As String = String.Format("{0}.{1}.{2}", groups(1), groups(2), groups(3))
I will never get this, but Perfect. Thank you

I actually needed the .swf and instead of replacing the "_" with ".", it wasn't needed. I was confused
haha didn't mean to click thanks, was trying to download the source to look at it. How are you retrieving the html document?
He's using Regex..basically it lets you sort/find strings... like how * and ? are for wildcards in dos, but on steroids.

If you want, try String.IndexOf()

basically it will give you the index where it finds a string, for example:

Dim testString as string = "<form name=something action=somethingelse ...> "
Dim leftLoc as Int32 = testString.Indexof("<") '' should = 1
Dim rightLoc as Int32 = testString.IndexOf(">") '' should = end of string

Dim contents as string = Mid(testString, leftLoc, rightLoc)

^^ mess around with it. some string functions are 0 based, some are 1 based, I can't remember. If you play with it for a minute, you'll either get what you expect, or one letter short, and you'll know you got index off by 1 lol

Also, IndexOf() can take a 'start' index, so once you find the first '<', you can find the next one by
Dim indxTwo as Int32 = testString.IndexOf("<",leftLoc + 1)


the +1 might be wrong
Quote Originally Posted by abuckau907 View Post
haha didn't mean to click thanks, was trying to download the source to look at it. How are you retrieving the html document?
He's using Regex..basically it lets you sort/find strings... like how * and ? are for wildcards in dos, but on steroids.

If you want, try String.IndexOf()

basically it will give you the index where it finds a string, for example:

Dim testString as string = "<form name=something action=somethingelse ...> "
Dim leftLoc as Int32 = testString.Indexof("<") '' should = 1
Dim rightLoc as Int32 = testString.IndexOf(">") '' should = end of string

Dim contents as string = Mid(testString, leftLoc, rightLoc)

^^ mess around with it. some string functions are 0 based, some are 1 based, I can't remember. If you play with it for a minute, you'll either get what you expect, or one letter short, and you'll know you got index off by 1 lol

Also, IndexOf() can take a 'start' index, so once you find the first '<', you can find the next one by
Dim indxTwo as Int32 = testString.IndexOf("<",leftLoc + 1)


the +1 might be wrong
I used a simple function return the webpage source

Code:
Public Function GetBuild() As String        Dim s As String = String.Empty
        Dim wRequest As WebRequest
        Dim wResponse As WebResponse
        Dim sReader As StreamReader


        wRequest = WebRequest.Create("URL")
        wResponse = wRequest.GetResponse
        sReader = New StreamReader(wResponse.GetResponseStream)
        s = sReader.ReadToEnd
        sReader.Close()
        Return s
    End Function
well if regex is working for you, awesome. it's way more complex that string.indexof(). But if you ever need to pull 1 string from inside another, it can work.

but since you read the page into a string variable..maybe try .IndexOf(). Or save it for later. But it comes in handy.
Posts 110 of 10 · Page 1 of 1

Post a Reply

Similar Threads

Tags for this Thread

None

Need help?