Bruce W. Darby wrote:
<snip>
Does this algorithm take into account that the space is also a character to
the computer?
the algorithm was:
CharNumber <- 1
Buffer <- ""
For every char C in the string
If CharNumber is even then append C to Buffer
return the Buffer
Yep, but notice the algorithm is wrong (ouch!). I forgot to increment
CharNumber inside the loop (damn, I keep doing that). The corrected
algorithm would be:
CharNumber <- 1
Buffer <- ""
For every char C in the string
If CharNumber is even then append C to Buffer
Increment CharNumber
return the Buffer
And that would lead to the following code (I assume the orignal
homework already passed its due time, so let's enlighten the OP)
Function EvenChars(Text As String) As String
Dim CharNumber As Integer = 1
Dim Buffer As New System.Text.StringBuilder
For Each C As Char In Text
If CharNumber Mod 2 = 0 Then
Buffer.Append(C)
End If
CharNumber += 1
Next
Return Buffer.ToString
End Function
Regards,
Branco.