I know, that's why it's O(n^2). As I said, even so.. But if the input is long then an approach using splitting ought to be used instead.
It'd be nice to have something like String.Buffer for parsing too. Maybe it could be extended with functions like get_char, has_prefix, get_prefix, sscanf, etc.