判断两个字符串中每个字符的个数是否相等。
“ABC”, “ACB” return true
“AABC”, “ABCD” return false代码:
Option Explicit
Option Base 1Public Function isSample(str1 As String, str2 As String) As BooleanDim array1() As String
Dim array2() As String
Dim i As Integer
Dim flag As BooleanIf Len(str1) = Len(str2) Then flag = True
ReDim array1(Int(Len(str1)))
ReDim array2(Int(Len(str2)))
For i = 1 To Len(str1)
array1(i) = Mid(str1, i, 1)
array2(i) = Mid(str2, i, 1)
Next i
'For i = LBound(array1) To UBound(array1)
' Print array1(i)
'Next i
Sort (array1) ''''''''''''提示缺少数组或用户定义类型的错误
Sort (array2)
If array1 = array2 Then
isSample = True
Else
isSample = False
End If
End FunctionPrivate Function Sort(arr1() As String)
Dim i As Integer, j As Integer
Dim temp As String
For i = LBound(arr) To UBound(arr1)
For j = UBound(arr) To i
If arr(j) < arr(j - 1) Then
temp = arr(j - 1)
arr(j - 1) = arr(j)
arr(j) = temp
End If
Next j
Next i
End FunctionPrivate Sub Command1_Click()
Dim str1 As String, str2 As String
str1 = "ABC"
str2 = "ACB"
If isSample(str1, str2) Then
MsgBox ("字符串相等")
Else
MsgBox ("字符串不等")
End If
End Sub
什么原因呢?
“ABC”, “ACB” return true
“AABC”, “ABCD” return false代码:
Option Explicit
Option Base 1Public Function isSample(str1 As String, str2 As String) As BooleanDim array1() As String
Dim array2() As String
Dim i As Integer
Dim flag As BooleanIf Len(str1) = Len(str2) Then flag = True
ReDim array1(Int(Len(str1)))
ReDim array2(Int(Len(str2)))
For i = 1 To Len(str1)
array1(i) = Mid(str1, i, 1)
array2(i) = Mid(str2, i, 1)
Next i
'For i = LBound(array1) To UBound(array1)
' Print array1(i)
'Next i
Sort (array1) ''''''''''''提示缺少数组或用户定义类型的错误
Sort (array2)
If array1 = array2 Then
isSample = True
Else
isSample = False
End If
End FunctionPrivate Function Sort(arr1() As String)
Dim i As Integer, j As Integer
Dim temp As String
For i = LBound(arr) To UBound(arr1)
For j = UBound(arr) To i
If arr(j) < arr(j - 1) Then
temp = arr(j - 1)
arr(j - 1) = arr(j)
arr(j) = temp
End If
Next j
Next i
End FunctionPrivate Sub Command1_Click()
Dim str1 As String, str2 As String
str1 = "ABC"
str2 = "ACB"
If isSample(str1, str2) Then
MsgBox ("字符串相等")
Else
MsgBox ("字符串不等")
End If
End Sub
什么原因呢?
解决方案 »
- VB6.0 mshflexgrid问题请高手解答! 输入表格使用TEXTBOX+mshflexgrid完成。
- VB取得屏幕某点的颜色问题(运行一段时间后出错)
- 判断WebBrowser1.Document.All.Item(i)是否存在
- 查询出现了问题,各位能帮我解决吗?
- help me
- 如何取出本机的计算机名,及所属的域。
- 求助Datareport问题!!!急
- 在用mciSendString或PlaySound来播放声音后,声音资源得不到释放,为什么???
- MDI窗体如何控制子窗口菜单不覆盖父窗口菜单 ?急!
- 求教SQL数据库的Image类型的字段的操作。
- cls方法
- 如何去掉对话框编辑时的网格?
Sort (array2) 与上一行相同的方式修改
array1 = array2 会报错的,数组之间不能进行比较运算