check length of string before indexing