Use slice instead of charAt