0

Looking for the simplest way to extract values from a string. For example consider the following:

Dim args As String = "/firstname:Bob /lastname:Jones"

To simplify, I need to be able to popup a box that says "Firstname = Bob" or "Lastname = Jones"

2
  • @Gens: I only wish. Little too old for homework :) Commented Jun 13, 2011 at 13:24
  • Could try something like this to do the work for you? (Assuming you're parsing command line args) commandline.codeplex.com or nconsoler.csharpus.com Commented Jun 13, 2011 at 13:44

3 Answers 3

1

Have you tried using the Split method on a string. It should look something like this:

Dim arr() as string
arr=args.Split("/")
Dim i as integer
    For i=0 to arr.GetLength(0)
    arr(i)=arr(i).Trim.Replace(":", "=")
Next
Sign up to request clarification or add additional context in comments.

Comments

0

I would use the Split function to create an array of words, then read them in order:

char[] sep = new char[2];
sep[0] = '/';
sep[1] = ':';
string values = "/firstname:Bob /lastname:Jones";
string[] sites = values.Split(sep);
foreach (string s in sites) {
Console.WriteLine(s);
}

This post is also useful! http://www.techrepublic.com/article/easily-parse-string-values-with-net/6030362

1 Comment

you would then in the look do an even or odd technique to grab the field name, vs. its value
0

Using Regex this pattern can help:

(?<identifier>[a-z]+)(?<value>[a-z]+)

See how it works.

You can iterate on all groups and can extract identifier and value.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.