Extract a value from a string
Hello,
Can you advise me what is the best way to get '123456789' from the string
HTML Code:
<Log xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns="http://www.nrf-arts.org/IXRetail/namespace/">
<Transaction SourceSystem="1">
<RetailStoreID>999</RetailStoreID>
<RevenueCenterID>0</RevenueCenterID>
<WorkstationID>123456789</WorkstationID>
<RegisterTransactionNumber>122</RegisterTransactionNumber>
</Transaction>
</Log>
Thanks
Re: Extract a value from a string
You can use either an XmlReader object or Regex.
Re: Extract a value from a string
Using .IndexOf() would be a shorter way, but regex would probably be simpler.
Re: Extract a value from a string
try this:
vb Code:
Dim testStr As String = "<WorkstationID>123456789</WorkstationID>"
Dim rx As New Regex("(?<=<WorkstationID>)\d+(?=</WorkstationID>)")
MsgBox(rx.Match(testStr).Value)
don't forget to import regex:
vb Code:
Imports System.Text.RegularExpressions