0

I have string as below.

X:= FMLVAR("Function1", "Var1");

I would like parse the above string and get the 2 arguments ("Funtion1" and "Var1"). FMLVAR is function which accepts 2 strings as arguments.

At present, I am using string manipulation function such as IndexOf and substring to process the above string and strip out those arguments.

Is there any better way doing this? Possibly using regular expression.

Any advice is much appreciated.

Thanks

Alan

2
  • You can show your current code, but I guess it would be better than using REGEX. Commented May 9, 2013 at 4:40
  • If you're going to do this in a generic sense, it might be better to write and use a parser. Commented May 9, 2013 at 4:57

1 Answer 1

1

Try something like this:

var s = "X:= FMLVAR(\"Function1\", \"Var1\");";

var match = new Regex(@"FMLVAR\(""(.+?)"", ""(.+?)""\);").Match(s);

var arg1 = match.Groups[1];
var arg2 = match.Groups[2];
Sign up to request clarification or add additional context in comments.

1 Comment

Note that this does not allow to add or remove spaces.

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.