Problems using the String.substing function for comparing letters in words

I’m trying to create a hangman based geocache based on an Arduino Uno. I’ve downloaded a sketch I found online and having corrected artefacts and modified the code to include an L2C display it will now compile and run but always returns the wrong result.

Essentially the code selects a word from an array and the user chooses a letter using a pot and pressing a button. The code then compares the chosen letter with each letter in the selected word. it is this comparison stage that fails. I’ve added a number of Serial.println lines to check what is being compared and everything appears in order.

The comparison is carried out using the string.substring function as shown in the code below. guessWord is the word selected by the code and wordSize is the number of letters in the word.
guessletter the letter chosen by the user.

for (int i = 0; i < wordSize; i++)
      {
        Serial.print(i);                                                          // For error trapping
        Serial.println(guessWord.substring(i, i + 1));              // For error trapping
        if (guessWord.substring(i, i + 1) == guessLetter)
        {
          Serial.print("I am here");                                       // For error trapping
          lcd.setCursor(i + 3, 1);   
          lcd.print(guessLetter);
          gotOne = 1;
          totalRight = totalRight + 1;
        }

I’ve looked at this for some time and it seems that the use of the string.substring function is OK. Am I missing something? There is a comment in the original code that says it must be run using IDE Version 0021, I’m using IDE v 1.8.9, is this the problem? The use of string.substring is certainly current.

Thanks in advance for any assistance, I’ve included the full code as an attachment, it was too large to embed.

Hangman.ino (11 KB)

must be something in your other code you didnt post. here is a working example to help you out

String thing = "RUBBERCHICKEN";
String turn="";
void setup() {


 byte i = thing.length();
 while(i>0){i--;turn=turn+"-";}
Serial.begin(9600);
guess("N");
guess("B");
}

void loop() {
  // put your main code here, to run repeatedly:

}

void guess(String g){
 
  int i = thing.length();
  while(i>0){i--;
  if(thing.substring(i,i+1)==g){
  
    turn = turn.substring(0,i)+g+turn.substring(i+1);
    Serial.println(turn);
    }
  
  }
  
  
  
  }

Why do you think you need to use the substring method to get one character from the String? The String class has a method to do just that. In addition, it overloads the operator, so you can do something like this:

   int len = guessWord.length();
   for(int i=0; i<len; i++)
   {
      if(guessWord[i] == guessLetter)
      {
         // The letter appears in the word at least once
      }
   }

Thanks for the replies guys, I'll have a go with these suggestions.