Hi there,

I'm making a Hangman game and stuck on this part:

public void Game(string letter)
        {
            if(word.Contains(letter))
            {
                int index = word.IndexOf(letter);
            }
        }

I am testing whether my string variable word contains a letter. If it does, it gets the index. (Yep, I used the IndexOf class) Now what I want to dos is to change a label that's on my form from _ _ _ _ _ to, for example, A _ _ _ _ where the word is actually APPLE.

In the class, I randomly select a word from an array, and put that word in a string called word. Then I set the label on my form from it's initial value "" which is nothing to a bunch of underscores, depending of course how big the word is. So if the random word is for example: Earth, then the label on the form would look like this: _ _ _ _ _.

So again, how would I go about changing the same index of the label as to the word(that's if the letter is in the word).

Help!

Just one think: What will happen with characters P in your case? There are two P letters in your word, so which index will be chosen for it?
This is not a good way to contiune. Just to make you think a bit better.

Mitja

You asked the same question here

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.