Solved

Parse string of data

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

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

Maximize Your Threat Intelligence Reporting

Reporting is one of the most important and least talked about aspects of a world-class threat intelligence program. Here’s how to do it right.

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
Custom auto number 6 51
Tabcontrol Caption? 1 25
Create XML 5 34
Convert to Hour/minute textbox and compare 3 36
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…
Calculating holidays and working days is a function that is often needed yet it is not one found within the Framework. This article presents one approach to building a working-day calculator for use in .NET.
In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…
This video explains how to create simple products associated to Magento configurable product and offers fast way of their generation with Store Manager for Magento tool.

746 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

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now