有没有搞错阿~要写全面性~有奖品 = =
程序代码:
Option Explicit
Private Sub Form_Load()
Dim Source() As String, TempString As String
Dim Num As Variant, LenNum As Integer, NewString As String
Dim i As Integer, iCount As Integer
TempString = Trim(InputBox("Input String ?"))
ReDim Source(Len(TempString) - 1)
For i = 0 To UBound(Source)
Source(i) = Mid(TempString, i + 1, 1)
Next i
Num = Trim(InputBox("What Index ?"))
If IsNumeric(Num) = True Then
For i = 0 To UBound(Source)
NewString = NewString & Source(i)
Next i
If Num < Len(TempString) Then
For i = Num - 1 To 1 Step -1
NewString = NewString & Source(i)
Next i
End If
ElseIf CheckNum(CStr(Num), iCount) = True Then
LenNum = InStr(TempString, Num)
If LenNum < Len(TempString) Then
NewString = Num & Mid(TempString, LenNum + iCount, Len(TempString) - LenNum + iCount)
For i = Len(TempString) - Len(NewString) To 1 Step -1
NewString = NewString & Mid(TempString, i, 1)
Next i
ElseIf LenNum = Len(TempString) Then
NewString = TempString
Else
MsgBox "Error !"
Exit Sub
End If
End If
MsgBox NewString
End Sub
Private Function CheckNum(Num As String, iCount As Integer) As Boolean
Dim i As Integer
CheckNum = False: iCount = 0
For i = 0 To Len(Num) - 1
If (Asc(Mid(Num, i + 1, 1)) > 47 And Asc(Mid(Num, i + 1, 1)) < 58) Or (Asc(Mid(Num, i + 1, 1)) > 64 And Asc(Mid(Num, i + 1, 1)) < 91) Or (Asc(Mid(Num, i + 1, 1)) > 96 And Asc(Mid(Num, i + 1, 1)) < 123) Or (Asc(Mid(Num, i + 1, 1)) = 32) Then
CheckNum = True
iCount = iCount + 1
Else
CheckNum = False: Exit For
End If
Next i
End Function
写到一半还当机~害我又重写~有判断的ASCII不能随便乱输入~
我寫的比你出的題目更複雜~原來是用空白切開就行~我把關鍵字以前的字符全部倒過來寫~
我程序可以判断你拿来比对的是数字或是字符~各有各的处理方式~
[
本帖最后由 wube 于 2011-5-13 23:02 编辑 ]