Find part of string in array, replace entire row with that part of string if found Following is the string: (I'm getting that from config file so its not constant):

string sequence = "Concat({ACCOUNT_NUM},substring(FormatDate(yyyyMMddHHmmss,DateNow())
,2,12), GetLast(GetNextSequence(seq_relation),1))";


It contains multiple custom methods and I want them somewhere in the same order as they appear in the above string. Following is the strategy I applied:

string[] arbitrary = sequence .Split('(').ToArray();

string[] methodsNmore = arbitrary.Take(arbitrary.Length - 1).ToArray();

string[] array2 = methodsNmore.Where(strr =&gt; strr.Contains(',')).ToArray();

string[] methods = array2.Select(str =&gt; str.Substring(str.LastIndexOf
                                         (',') + 1, str.Length - str.LastIndexOf
                                         (',') - 1)
                                        ).ToArray();

for (int i = 0; i &lt; methods.Length; i++)
{
   string row = Array.Find(methodsNmore, item =&gt; item.Contains(methods[i]));

   int ii = Array.IndexOf(methodsNmore, row);

   methodsNmore[ii] = methods[i];
}


The resulting array, methodsNmore, now contains only the names of methods in the same order as in above string sequence.

Is there any other elegant way of doing it?
You can use a regular expression:

string[] names =
  Regex.Matches(sequence, @"([A-Za-z_]\w*)\(").Cast&lt;Match&gt;()
  .Select(m =&gt; m.Groups[1].Value).ToArray();