traverse through a string

I grab the following HTML from my page.

now I want a function which returns me all 'values' of a certain 'class'

e.g. If I give the function this HTML and a class name, say 'nenMeterRegister' then it should find the corresponding 'value' in same row , do that for every element which has a class 'nenMeterRegister' and returns an array of those elements.
how do I do this?
<table>
<tr class="nenDataRow">
                        <td>
                            <input type="checkbox" class="nenMakeInvalid" />
                        </td>
                        <td>
                            <input type="text"  class="nenMeterRegister" disabled="disabled" value="643234-1" />
                        </td>
                        <td>
                            <input type="text" class="nenNmiSuffix" disabled="disabled" value="11" />
                        </td>
                        
                    </tr>
<tr class="nenDataRow">
                        <td>
                            <input type="checkbox" class="nenMakeInvalid" />
                        </td>
                        <td>
                            <input type="text"  class="nenMeterRegister" disabled="disabled" value="643234-1" />
                        </td>
                        <td>
                            <input type="text" class="nenNmiSuffix" disabled="disabled" value="11" />
                        </td>
                        
                    </tr>
</table>

Open in new window

manivineetAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Alfred A.Commented:
Check this out:

http://www.quirksmode.org/dom/intro.html

for getting the value of an attribute:

for example:

txt=xmlDoc.getElementsByTagName("input")[0].getAttribute("nenMeterRegister");

see below for details:

http://www.w3schools.com/dom/dom_nodes_get.asp

I hope this helps.
0
manivineetAuthor Commented:
@Alfred1 : Thanks, but i need to do this with VB.Net
so in essence i need to get the values, as if this were a normal string and not HTML data.
0
Alfred A.Commented:
Try this.  It is not complete but I just provided some idea on how to get it.  I hope it helps.
Public Sub GetNenMeterRegisterValues()        
        Dim objStreamReader As New StreamReader("C:\traverse.txt")
        Dim strText As String = objStreamReader.ReadToEnd
        Dim strLength As Integer = strText.Length
        Dim Pos As Integer = 1
        Dim SecondPos As Integer = 0
        Dim nenMeterRegisterValues As String
        Do
            Pos = InStr(Pos, strText, "class=""nenMeterRegister""")
            If Pos > 0 Then
                SecondPos = InStr(Pos, strText, "value=""")
                If SecondPos > 0 Then
                    'Get Value
                    nenMeterRegisterValues = nenMeterRegisterValues & (strText, SecondPos + 7, 8) & ","
                    Pos = SecondPos
                End If
            Else
                Exit Do
            End If
        Loop
End Sub

Open in new window

0
Alfred A.Commented:
Oops.  Correction on the code I provided.  I am posting it again.  Mid is missing in line 14.
Public Sub GetNenMeterRegisterValues() 
        Dim objStreamReader As New StreamReader("C:\traverse.txt")
        Dim strText As String = objStreamReader.ReadToEnd
        Dim strLength As Integer = strText.Length
        Dim Pos As Integer = 1
        Dim SecondPos As Integer = 0
        Dim nenMeterRegisterValues As String = String.Empty
        Do
            Pos = InStr(Pos, strText, "class=""nenMeterRegister""")
            If Pos > 0 Then
                SecondPos = InStr(Pos, strText, "value=""")
                If SecondPos > 0 Then
                    ''Get Value
                    nenMeterRegisterValues = nenMeterRegisterValues & Mid(strText, SecondPos + 7, 8) & ","
                    Pos = SecondPos
                End If
            Else
                Exit Do
            End If
        Loop
End Sub

Open in new window

0
ddayx10Commented:
There are a million ways to parse strings, so this is just one approach, but it works fine with the sample you provided :)

    Public Function GetValuesFromHtmlString(ByVal html As String, ByVal className As String) As String()
        Dim rValue As New List(Of String)
        Dim x As String() = html.Split(New [Char]() {CChar(vbCrLf)})
        Dim pattern As String = "(\S)"

        For Each s As String In x
            If Not String.IsNullOrEmpty(s.Trim) And Regex.IsMatch(s, pattern) Then
                If s.Trim.Contains("class=" & ControlChars.Quote & className) And s.Trim.Contains("value=") Then
                    Dim sIdx As Integer = s.Trim.IndexOf("value=") + 7
                    Dim eIdx As Integer = s.Trim.IndexOf(ControlChars.Quote, sIdx)
                    rValue.Add(s.Trim.Substring(sIdx, eIdx - sIdx))
                End If
            End If
        Next
        Return rValue.ToArray()
    End Function
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Visual Basic.NET

From novice to tech pro — start learning today.