FakeNameGenerator source

This snippet parse the fakenamegenerator.com page and gets the information for you!


Public Structure Info
        Dim FirstName, MidName, LastName, State, City, Addy, Zip, Phone, _
        Email, Birthday, Job As String
    End Structure

    Public Shared Function GetFakeName() As Info
        Dim Str As String = New Net.WebClient(). _
            DownloadString("http://it.fakenam" & _
                           "egenerator.com/gen-random-it-it.php")
        Dim I As New Info
        I.FirstName = GetBetween(Str, "<span class=""given-name"">", "</span>")
        I.MidName = GetBetween(Str, "<span class=""additional-name"">", "</span>")
        I.LastName = GetBetween(Str, "<span class=""family-name"">", "</span>")
        I.State = GetBetween(Str, "<span class=""region"">", "</span>")
        I.City = GetBetween(Str, "<span class=""locality"">", "</span>")
        I.Addy = GetBetween(Str, "<span class=""street-address"">", "</span>")
        I.Zip = GetBetween(Str, "<span class=""postal-code"">", "</span>")
        I.Phone = GetBetween(Str, "<li class=""tel""><span class=""value"">", _
        "</span>")
        I.Email = GetBetween(Str, "<li class=""email""><span class=""value"">", _
        "</span>")
        I.Birthday = GetBetween(Str, "<li class=""bday"">", "</li>")
        I.Job = GetBetween(Str, "<li class=""title"">", "</li>")
        Return I
    End Function
    Private Shared Function GetBetween(ByRef strSource As String, _
    ByRef strStart As String, ByRef strEnd As String, _
    Optional ByRef startPos As Integer = 0) As String
        Dim iPos As Integer, iEnd As Integer, lenStart As Integer = strStart.Length
        Dim strResult As String
        strResult = String.Empty
        iPos = strSource.IndexOf(strStart, startPos)
        iEnd = strSource.IndexOf(strEnd, iPos + lenStart)
        If iPos <> -1 AndAlso iEnd <> -1 Then
            strResult = strSource.Substring(iPos + lenStart, iEnd - (iPos + lenStart))
        End If
        Return strResult
    End Function

Usage:

Dim I As Info = GetFakeName()
MsgBox(I.FirstName)

GetBetween Function

I think this function is very useful.
It allows to get the text which is between to other strings from a entire long string/web page.

Mainly it’s used to parse informations in webpages.

Private Shared Function GetBetween(ByRef strSource As String, _
ByRef strStart As String, ByRef strEnd As String, _
Optional ByRef startPos As Integer = 0) As String
        Dim iPos As Integer, iEnd As Integer, lenStart As Integer = strStart.Length
        Dim strResult As String
        strResult = String.Empty
        iPos = strSource.IndexOf(strStart, startPos)
        iEnd = strSource.IndexOf(strEnd, iPos + lenStart)
        If iPos <> -1 AndAlso iEnd <> -1 Then
            strResult = strSource.Substring(iPos + lenStart, iEnd - (iPos + lenStart))
        End If
        Return strResult
    End Function