Function Check(ByVal str As String) As Boolean
Dim re As Boolean = True
Dim length As Integer
length = str.Length
Dim mid As Integer
mid = Math.Floor(length / 2)
Dim i As Integer = 0
Dim j As Integer = 0
Dim k As Integer = 0
Dim firstStr As String
Dim lastStr As String
If length Mod 2 <> 0 Then
For i = 0 To mid
j = i
k = mid * 2 - i
firstStr = str(j)
lastStr = str(k)
If firstStr <> lastStr Then
re = False
Exit For
End If
Next
Else
re = False
End If
Return re
End Function
vb的语法忘了,我用.net些吧
char[] ch=str.ToChar();
bool b=false;
if(ch.length\2!=0)
{
for(int i=0;i<=(ch.length-1)/2;i++)
{
if(ch[i]==ch[ch.length-1-i])
{
b=true;
continue;
}
else
{
b=false;
break;
}
}
return b;
}
If str = Strings.StrReverse(str) Then
Console.WriteLine("回文")
Else
Console.WriteLine("不是回文")
End If
StrReverse 字符串反转函数!