Public Class Form1
Private Sub Button1_Click(sender As System.Object, e As System.EventArgs) Handles Button1.Click
Dim counter As Integer = 0, counter2 As Integer = 0, temp As Integer = 0
Dim Half As Integer
Dim Test As Boolean = False
RichTextBox1.Text = RichTextBox1.Text.Replace(" ", "")
RichTextBox1.Text = RichTextBox1.Text.Replace(".", "")
RichTextBox1.Text = RichTextBox1.Text.Replace(vbLf, "")
Dim j As Integer = RichTextBox1.Text.Length
If RichTextBox1.Text.Length Mod 2 Then
' just for help to test MsgBox("You've put an odd no. of Chars.")
Half = Math.Floor((RichTextBox1.Text.Length - 1) / 2)
For i = 0 To Half - 1
For j = RichTextBox1.Text.Length - 1 To 0 Step -1
If i < Half Then
If RichTextBox1.Text.Chars(i) = RichTextBox1.Text.Chars(j) Then
MsgBox(RichTextBox1.Text.Chars(i) & RichTextBox1.Text.Chars(j))
counter = counter + 2
Else
MsgBox("Same chars at respective places are " & counter)
Test = True
MsgBox("Test became true")
Exit For
End If
i += 1
Else
'i += 1
End If
' i = i + 1
Next
If Test = True Then Exit For
Next
Else
' just for help to test MsgBox("You've put an even no. of Chars.")
Half = Math.Floor((RichTextBox1.Text.Length) / 2)
MsgBox(Half)
For i = 0 To Half - 1
For j = RichTextBox1.Text.Length - 1 To Half Step -1
If i < Half Then
If RichTextBox1.Text.Chars(i) = RichTextBox1.Text.Chars(j) Then
' MsgBox(RichTextBox1.Text.Chars(i) & RichTextBox1.Text.Chars(j))
counter = counter + 2
Else
MsgBox("Same chars at respective places are " & counter)
Test = True
MsgBox("Test became true")
Exit For
' j -= 1
End If
i += 1
' Exit For
End If
Next
If Test = True Then Exit For
Next
End If
If counter / 2 = Half Then
MsgBox("This text is a palindrome, it doesn't need any additional character.")
Else
' For j = RichTextBox1.Text.Length - 1 To 1 Step -1
'If RichTextBox1.Text.Chars(j) = RichTextBox1.Text.Chars(j - 1) Then
For i = 0 To RichTextBox1.Text.Length - 2
If RichTextBox1.Text.Chars(i + 1) = RichTextBox1.Text.Chars(i) Then
counter2 = counter2 + 1
MsgBox("The no. of same straight chars atm is " & counter2)
If temp <= counter2 Then
temp = counter2
MsgBox("Biggest same straight char no. is " & temp)
End If
MsgBox(counter2)
Else
counter2 = 0
End If
Next
If counter2 <= temp Then
counter2 = temp
End If
MsgBox("Temp =" & temp)
MsgBox("This text is not a palindrome, it needs " & (RichTextBox1.Text.Length - 1 - counter - temp) & " chars to become one.")
End If
'MsgBox(counter)
End Sub
End Class