VB.NET: Extract Xml attribute related to symbol
Say i have these Xml tag...
Code:
<book title=”Harry Porter page="1_9”>
<new id=”100”>China News</new>
<new id=”101”>Street paper</new>
<new id=”0”>none</it>
…….
<new>….</new>
</book>
how do i exactly extract the 1 and 10 separately from "1_9"
Now i am using substring to extract 1 and 9, it works well...
But if the 9 becomes 10 (double digits), it will have exception if i have to loop the Xml and send the maxpage to the server...
Code:
page = xdoc.SelectSingleNode("//book/@page").Value.Substring(0, 1)
maxPage = xdoc.SelectSingleNode("//book/@page").Value.Substring(2, 1)
Thanks
Re: VB.NET: Extract Xml attribute related to symbol
Use the underscore to parse the string into the 2 components, i.e.
VB Code:
Dim value as String = xdoc.SelectSingleNode("//book/@page").Value
Dim page As String = value.Substring(0, value.IndexOf("_"))
Dim maxPage As String = value.Substring(value.IndexOf("_") + 1)