-2

I need you help I have one string like

a1 + b1 + ( v1 + g1 ) * 10

I need to retrieve only a1,b1,v1,g1 any idea

2 Answers2

1

I would use RegEx to filter the desired output. Assuming that your result always starts with a small letter and ends with a digit [a-z][0-9]

string input = "a1 + b1 + ( v1 + g1 ) * 10";
List<string> Result = Regex.Matches(input, @"[a-z][0-9]")
                            .Cast<Match>()
                            .Select(x => x.Value)
                            .ToList();
fubo
  • 44,811
  • 17
  • 103
  • 137
0

I'd go after it using a recursive descent parser. It may seem as an overkill to start with but it will work for all sorts of expressions.

Here's a good introduction to the theory.

Tomaz Stih
  • 529
  • 3
  • 10