Generic string parse utility method