I am currently working on a project that has hit a bit of a snag. I have the following string;

<td class="bld"><span id="ref_12590587_l">5,304.48</span>

I want to cut this string so that only the "5,304.48" is remaining. I would also then like to remove the comma.

Thanks

Recommended Answers

All 3 Replies

Using some Regex will do:

Dim text As String = "<td class=""bld""><span id=""ref_12590587_l"">5,304.48</span>"
Dim regularExpressionPattern As String = "\>(.*?)\<"
Dim re As New Regex(regularExpressionPattern)
Dim dec As Decimal
Dim str As String = ""
For Each m As Match In re.Matches(text)
    str = m.Value.Replace(">", "").Replace("<", "")
    If str.Length > 0 Then
        If str.Contains(",") Then
            str = str.Replace(",", "")
        End If
    End If
Next
commented: Good job, Mitja. +5

.

   Function GetValue() As String
    Dim str As String = "<td class= ""bld"" ><span id=""ref_12590587_l"">5,304.48</span>"
    Dim strIndex As Integer = str.LastIndexOf("""")
    Dim str_tmp As String = str.Substring(strIndex + 2)
    Dim lstIndex As Integer = str_tmp.LastIndexOf("<")
    Dim str_fnl As String = str_tmp.Substring(0, lstIndex)
    If str_fnl.Contains(",") Then
        str_fnl = str_fnl.Replace(",", "")
    End If
    Return str_fnl
   End Function
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.