1

The String Like this:

Select(GetName(null),GetID(22),1,GetID(),GetData("T",100),true);

I want to split the string (function).

Return like this:

String MainFunName = "Select()"
String MainFunName_Parameters="GetName(null),GetID(22),1,GetID(),GetData("T",100),true"
int MainFunName_Parameters1_Count = 6;

GetName(null)
GetID(22)
1
GetID()
GetData("T",100)
true

I was try

_str.Substring(_str.IndexOf("(") + _str.Length).Split(',').Count();

It will get 7 not 6, the GetData("T",100) was splited to two part

GetData("T"
100)

I would like to know how to use the regex group to split this string? thanks

1 Answer 1

1

You can use it like this:

String str = "Select(GetName(null),GetID(22),1,GetID(),GetData(\"T\",100),true)";
Match result = Regex.Match(str, @"^(\w+)\(([\w""]+(\(.*?\))?[\s,]*?)*\)$");

string outerMethodName = result.Groups[1].Value;
List<string> arguments = result.Groups[2].Captures.Cast<Capture>().Select(i => i.Value.TrimEnd(',')).ToList();

Console.WriteLine(outerMethodName);

int argumentLength = arguments.Count;
foreach (string argument in arguments)
{
    Console.WriteLine(argument);
}
Sign up to request clarification or add additional context in comments.

2 Comments

could you help me about "select()" and "select(1)" and "select(GetID(22))" etc. thank.
I updated the answer to consider spaces between arguments.

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.