Option ExplicitPrivate Sub Command1_Click() Dim intP As Integer Dim intL As Integer Dim strP As String strP = Text1.Text intL = Len(strP) If intL > 0 Then For intP = 1 To intL If (Asc(Mid(strP, intP, 1)) >= Asc("a") And Asc(Mid(strP, intP, 1)) >= Asc("z")) Or _ (Asc(Mid(strP, intP, 1)) >= Asc("A") And Asc(Mid(strP, intP, 1)) >= Asc("Z")) Then Exit For End If Next intP End If Text2.Text = CStr(intP) '首字母位置 End SubPrivate Sub Form_Load() Text1.Text = "77kfhdslhg" Text2.Text = "0" End Sub
Dim i As Integer a = "77kfh434d%^&slhg" For i = 1 To Len(a) If Not IsNumeric(Mid(a, i, 1)) Then Debug.Print i Exit For End If Next i
With CreateObject("vbscript.regExp") .Pattern = "[^\d]" MsgBox .Execute("77kfh434d%^&slhg")(0).firstindex + 1 End With
Option ExplicitPrivate Sub Command1_Click()
Dim intP As Integer
Dim intL As Integer
Dim strP As String
strP = Text1.Text
intL = Len(strP)
If intL > 0 Then
For intP = 1 To intL
If (Asc(Mid(strP, intP, 1)) >= Asc("a") And Asc(Mid(strP, intP, 1)) >= Asc("z")) Or _
(Asc(Mid(strP, intP, 1)) >= Asc("A") And Asc(Mid(strP, intP, 1)) >= Asc("Z")) Then
Exit For
End If
Next intP
End If
Text2.Text = CStr(intP) '首字母位置
End SubPrivate Sub Form_Load()
Text1.Text = "77kfhdslhg"
Text2.Text = "0"
End Sub
a = "77kfh434d%^&slhg"
For i = 1 To Len(a)
If Not IsNumeric(Mid(a, i, 1)) Then
Debug.Print i
Exit For
End If
Next i
.Pattern = "[^\d]"
MsgBox .Execute("77kfh434d%^&slhg")(0).firstindex + 1
End With