What would be a good way to parse a C-like or Lisp-like code into an array, using C#?
So for example, for a little snippet like the following:
if (number > 50) {
alert('Hello, World!');
}
I want to be able to store every word and symbol into an array.
But up until now I managed to output an array like the following:
[0] if
[1] (number
[2] >
[3] 50)
[4] {
[5] alert('Hello,
[6] World!');
[7] }
You see at array location 1
, where it says (number
? That's not really what I want. I want even that little parenthesis to be placed into its own array location.
What I was initially thinking on doing was to read every character of the code, and then start storing them into arrays accordingly. But that seems like I'm reinventing the wheel when parsing strings. Are there any simpler way of doing this?
p.s. I'm doing this because I want to learn proper string manipulation.