I am working on a project where I have strings with lots of brackets like ((A and B and (C or (D and E))) or F). I need to find a way to find the pairs and style or color them to show they are matching. For example, the brackets around "D and E" would be green, and the ones around "C or (D and E)" would be blue. For matching pairs I was using a stack but couldn't find a way to set colors, if theres a better way I'm open to try it. I'm working in asp.net and C#. Thanks!
Edit: here is the code that generates the string. terms is a list of values, innerConnector is either "and" or "or" based on user input, and child groups are groups within the larger group. (A and (B or C)) A would be a term, (B or C) would be a child group. I want to take the string this returns and apply the colors to the parentheses.
public string toString()
{
string str = "(";
if(terms.Count > 0)
{
for(int i = 0; i < terms.Count; i++)
{
if(i == 1)
{
str += terms[i];
}
else
{
str += " " + innerConnector + " " + terms[i];
}
}
}
if(children != null)
{
for(int i = 0; i < terms.Count; i++)
{
if(i == 1 && terms.Count == 0)
{
str += childGroups[i].toString();
}
else
{
str += " " + innerConnector + " " childGroups[i].toString();
}
}
}
str += ")";
}