Solved

Parse string of data

Posted on 2013-11-22
5
212 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 500 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

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Introduction When many people think of the WebBrowser (http://msdn.microsoft.com/en-us/library/2te2y1x6%28v=VS.85%29.aspx) control, they immediately think of a control which allows the viewing and navigation of web pages. While this is true, it's a…
It’s quite interesting for me as I worked with Excel using vb.net for some time. Here are some topics which I know want to share with others whom this might help. First of all if you are working with Excel then you need to Download the Following …
If you’ve ever visited a web page and noticed a cool font that you really liked the look of, but couldn’t figure out which font it was so that you could use it for your own work, then this video is for you! In this Micro Tutorial, you'll learn yo…
Add bar graphs to Access queries using Unicode block characters. Graphs appear on every record in the color you want. Give life to numbers. Hopes this gives you ideas on visualizing your data in new ways ~ Create a calculated field in a query: …

705 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