Ma l'input è sempre in quel formato?

Praticamente devi realizzare una sorta di parser ... potresti usare anche le regular expression ...