Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Split text to get certain value

Tags:

vb.net

How can I split this xml node to get only the number value?

<span>All Potatoes: 4</span>

Something like this:

Dim code as string = "<span>All Potatoes: 4</span>"
Dim splitrsult as string
Splitresult = splitresult("<span>All Potatoes:" & "</span>")
Msgbox(splitresult)

I'm newbie in this language, and help would be appreciate it. Thank you!

like image 491
qckmini6 Avatar asked Mar 14 '23 08:03

qckmini6


2 Answers

Handle the XML as XML! (not as a simple string)

Use this imports statement

Imports System.Xml.Linq

Then parse your string in order to get an Xml element and get its value

Dim code As String = "<span>All Potatoes: 4</span>"
Dim node = XElement.Parse(code)
Dim result As String = node.Value ' ==> "All Potatoes: 4"
like image 184
Olivier Jacot-Descombes Avatar answered May 03 '23 04:05

Olivier Jacot-Descombes


To get the number value using Regex: (It's simple. Never be afraid of Regex)

Dim code as string = "<span>All Potatoes: 4</span>"
resultString = Regex.Match(code, @"\d+").Value
like image 22
Fᴀʀʜᴀɴ Aɴᴀᴍ Avatar answered May 03 '23 06:05

Fᴀʀʜᴀɴ Aɴᴀᴍ