title: Substring working in an unexpected fashion
body: <p>I am programming a Hangman game in Visual Basic for some college homework (as much as I hate Visual Basic- I prefer C++), and I have got myself slightly stuck.
  When the player presses a letter on the on-screen keypad, the word needs to be checked for the presence of that letter, and to replace the specific character in the masked version of the string (a masked version of 'Apple' would be '*****', for example).</p>
  
  <p>To replace the character I am illiterating through the <code>word</code> string, and performing a <code>substring</code> operation to replace the character position in the <code>maskedWord</code>.</p>
  
  <p><img src="https://i.stack.imgur.com/5vmcW.png" alt="enter image description here"> </p>
  
  <p>The <code>Str = maskedWord.Substring(0, count) + CStr("A") + maskedWord.Substring(count + 1)</code> is fairly self-explanatory; we're cutting the character out and replacing it with the letter we want (in this case, 'A').
  I've searched and searched for the solution to this, but I haven't found anything apart from the <code>Mid</code> function, which doesn't work properly.</p>
  
  <p>I'm fairly sure that I programmed the 'Str = ' line correctly, but as can be seen in the screenshot, it doesn't work the way that had been intended. The word 'DUBITABLY' has the letter 'A' a character position '6', but instead the 'A' position in 'Str' is being put to position '1'.</p>
  
  <p>Why is this happening, and how could I get 'Str' to format in the intended way?
  I've verified that 'count' is being set correctly.</p>
  
  <p>The code (I added the 'MsgBox' and a couple of other lines as diagnostic):</p>
  
  <pre><code>Private Sub btnA_Click(sender As Object, e As EventArgs) Handles btnA.Click
          btnA.Enabled = False 'Deactivates the button, so the player cannot use it again.
          If (InStr(word, "A")) Then 'If the letter is in the string
              Dim count As Integer = 0
              For Each c As Char In word 'We go over every char in the word..
                  If (CStr(c) = "A") Then
                      Dim Str As String = maskedWord
                      'Str.Remove(count, 1).Insert(count, "A")
                      Str = maskedWord.Substring(0, count) + CStr("A") + maskedWord.Substring(count + 1)
                      MsgBox(Str)
                      count += 1
                  End If
              Next
          End If
      End Sub
  </code></pre>