fix string like '%1' throws TypeError

Use charAt() instead of index notation to get the test character.