Cheers stanav for the code. I tried your regular expression but that did not returns any matches (using VS and RegExLib.com).
I have now created a new solution that uses a list (from your posted code), vijy's regular expression and more regular expressions to remove HTML Tags.
This is all working fine, but I have run into a problem with the "Matches" part. I know that each match must contain 2 values. If a user was to enter a invalid stock code, the match would either = 0 Or 1 (From my testing). How can I detect this and log the error? Below is the code I am using
Code:' Read The Response Into A String Dim strHTML As String = str.ReadToEnd Dim strStartCut As String Dim strEndCut As String Dim strStartTag As String Dim strEndTag As String Dim strDesired As String ' Cut Out Only What We Need strStartTag = "<td class=""Normal"" align=""right"">" strEndTag = "</tr>" strStartCut = (InStr(1, strHTML, strStartTag, vbTextCompare) + Len(strStartTag)) strEndCut = (InStr(strStartCut, strHTML, strEndTag, vbTextCompare)) strDesired = Mid(strHTML, strStartCut, (strEndCut - strStartCut)) ' Strip HTML Tags Dim Pattern As String = "<[^>]*>" Dim R As New Regex(Pattern) strDesired = R.Replace(strDesired, "") Dim Pattern2 As String = "[<]" Dim S As New Regex(Pattern2) strDesired = S.Replace(strDesired, "<") Dim Pattern3 As String = "[>]" Dim T As New Regex(Pattern3) strDesired = T.Replace(strDesired, ">") 'Declare a list to hold prices Dim priceList As New List(Of Decimal) Dim expression As String = "([0-9]{1,}).([0-9]{1,})" Dim matches As System.Text.RegularExpressions.MatchCollection = System.Text.RegularExpressions.Regex.Matches(strDesired, expression) For Each Match As System.Text.RegularExpressions.Match In matches If Match.Value = 0 Or 1 Then Me.RichTextBoxError.Text += Date.Now + " - Data Not Available For UNLM Code " + MorningStarCode + vbCrLf Else priceList.Add(Decimal.Parse(Match.Value)) 'MessageBox.Show(Decimal.Parse(Match.Value)) End If Next 'Dim ExtractedPrices As String = "2B" & vbNewLine & ("00" & MATECode) & vbNewLine & sDate & vbNewLine & ("000000" & priceList.Item(0) & "00") & vbNewLine & ("000000" & priceList.Item(1) & "00") 'Dim Lines() As String = Split(ExtractedPrices.ToString, vbCrLf) 'Me.DataGridViewDD.Rows.Add(Lines)




Reply With Quote