0

I have strings in the format of:

httP;//whatvere[CanIncludeSpaces"].url -a -b -c

How do I get the arguments -a, -b, -c in a string array?

Thanks

9
  • are those strings supposed to represent actual hyperlinks, or is it jut a coincidence that the example you posted seems to resemble a hyperlink? Commented Oct 1, 2012 at 22:12
  • No the first part is a url, the arguments are regular args Commented Oct 1, 2012 at 22:15
  • The can include spaces part is delimited by []? Commented Oct 1, 2012 at 22:22
  • You could use regex to get it... Commented Oct 1, 2012 at 22:23
  • 1
    you can just reverse the string, split it on white spaces, loop through the strings and stop when you run into the first one that doesnt start with a dash(-) as each arg will (per your exmple) have the dash in front of it and they will all be at the end. Commented Oct 1, 2012 at 22:48

1 Answer 1

1

Here's what I came up with:

var str = "httP;//whatvere[CanIncludeSpaces\"].url -a -b -c";
var endOfUrl = str.LastIndexOf(".url") + 4;
var args = str.Substring(endOfUrl).Split(new[]{' '}, StringSplitOptions.RemoveEmptyEntries);
//args is ["-a", "-b", "-c"]
//also, the URL is easy to get:
var url = str.Substring(0, endOfUrl);
//url is now 'httP;//whatvere[CanIncludeSpaces"].url'
Sign up to request clarification or add additional context in comments.

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.