Solved

Parse string of data

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

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

This tutorial demonstrates one way to create an application that runs without any Forms but still has a GUI presence via an Icon in the System Tray. The magic lies in Inheriting from the ApplicationContext Class and passing that to Application.Ru…
Parsing a CSV file is a task that we are confronted with regularly, and although there are a vast number of means to do this, as a newbie, the field can be confusing and the tools can seem complex. A simple solution to parsing a customized CSV fi…
Microsoft Active Directory, the widely used IT infrastructure, is known for its high risk of credential theft. The best way to test your Active Directory’s vulnerabilities to pass-the-ticket, pass-the-hash, privilege escalation, and malware attacks …
This video shows how to use Hyena, from SystemTools Software, to bulk import 100 user accounts from an external text file. View in 1080p for best video quality.

828 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