OrElse
OrElse

Reputation: 9959

How can i select from string?

Dim str as string = "<request id=value1 type=value2>value3</request>"

How could select the values as follows...

Dim id as string = get the value of id (value1)
Dim type as string = get the value of type (value 2)
Dim ReadValue3 as string = get the value3

Upvotes: 1

Views: 555

Answers (2)

Roman A. Taycher
Roman A. Taycher

Reputation: 19477

Note it is possible to use linq with strings see http://msdn.microsoft.com/en-us/library/bb397915.aspx

you just wouldn't want to when dealing with xml

Upvotes: 0

Jon Skeet
Jon Skeet

Reputation: 1499860

Well, I can't see why you'd need to use LINQ itself, but you could certainly use LINQ to XML:

Dim element as XElement = XElement.Parse(str)
Dim id as String = CType(element.Attribute("id"), String)
Dim type as String = CType(element.Attribute("type"), String)
Dim value as String = element.Value

(Apologies if the VB has syntax issues... it's not my mother tongue, so to speak.)

Upvotes: 3

Related Questions