The basic problem you are probably having is that you aren't checking every character: a
loop automatically increments the variable, so when you don't find a match you skip a character automatically. Removing your whole
clause will probably fix that, but that is a poor way to do things.
I would rename your variables:
and I would set it to a silly value to start with.
I would then use a
loop to extract each character in turn:
Dim str As String = "hello paul"
Dim lastChar As Char = ControlChars.Lf
For Each thisChar As Char In str
If thisChar = lastChar Then
lastChar = thisChar