?
Solved

Parse string of data

Posted on 2013-11-22
5
Medium Priority
?
214 Views
Last Modified: 2013-11-26
How can I programmtically parse to get the "weather-type" value from this string

<value coverage="chance" intensity="light" weather-type="rain showers" qualifier="none">

I need to do this in VB.NET and return the value for the weather-type element

Any help would be appreciated
Thanks
JK
0
Comment
Question by:jknj72
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
5 Comments
 
LVL 50

Expert Comment

by:Lowfatspread
ID: 39669543
is this homework?

you could use Instr to find the start of  Weather type then add 14 to get the start position of the data.... after that you then need to copy all the c haracters until you find the next quote/ending quote

see http://social.msdn.microsoft.com/Forums/en-US/6f64af4e-1cdf-46ee-8a14-6021c2d64951/vbnet-search-for-stringword-in-strings
0
 
LVL 40
ID: 39669746
Dim startIndex As Integer = yourString.IndexOf("weather-type=") + 14
            Dim endIndex As Integer = yourString.IndexOf("""", startIndex)
            Dim result As String = yourString.Substring(startIndex, endIndex - startIndex)
0
 
LVL 63

Accepted Solution

by:
Fernando Soto earned 2000 total points
ID: 39669870
Hi jk;

You could also use a regular expression to get the value as shown below.

' The string you wish to parse
Dim weatherStr As String = "Your Input String Here."
' Get the weather-type from the string
Dim weather = Regex.Match(weatherStr, "(?i)weather-type=""([^""]+)")
' Test to see if weather-type was in the string and if so access the value
If weather.Success Then
    Console.WriteLine(weather.Groups(1).Value)
End If

Open in new window

0
 

Author Comment

by:jknj72
ID: 39675098
Thanks I will try these out today.

@Lowfatspread - not homework, its work
0
 

Author Closing Comment

by:jknj72
ID: 39677546
Thanks Fernando. Worked like a charm
0

Featured Post

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Article by: jpaulino
XML Literals are a great way to handle XML files and the community doesn’t use it as much as it should.  An XML Literal is like a String (http://msdn.microsoft.com/en-us/library/system.string.aspx) Literal, only instead of starting and ending with w…
Since .Net 2.0, Visual Basic has made it easy to create a splash screen and set it via the "Splash Screen" drop down in the Project Properties.  A splash screen set in this manner is automatically created, displayed and closed by the framework itsel…
Michael from AdRem Software explains how to view the most utilized and worst performing nodes in your network, by accessing the Top Charts view in NetCrunch network monitor (https://www.adremsoft.com/). Top Charts is a view in which you can set seve…
In this video, Percona Solution Engineer Dimitri Vanoverbeke discusses why you want to use at least three nodes in a database cluster. To discuss how Percona Consulting can help with your design and architecture needs for your database and infras…
Suggested Courses

764 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question