I have a small text string with xml like tags inside it:
<sub>A</sub>B<sup>C</sup>
I need to parse this text and perform actions based on the tags. So the above text will look like ABC in my target application (MS Excel -- Excel can parse and format this string if I paste it but not if I just enter it in a cell).
What is the best way to parse this type of tag based text in terms of performance. The formatting code is going to be called very frequently and I want to minimize the overhead as much as possible. I can think of the following options:
- Parse it character by character using the Indexer keeping track of when the tag started/ended
- Use Regular Expressions
- Load it into some XML/HTML DOM Parser and iterate through the nodes
Which one do you think will have the least performance impact? Any other way I can get the task done?