+ -
当前位置:首页 → 问答吧 → 一个字符串,包含数字和字母和字符,怎么得到字母或字符首次出现的位置?

一个字符串,包含数字和字母和字符,怎么得到字母或字符首次出现的位置?

时间:2011-10-03

来源:互联网

比如 77kfh434d%^&slhg ,我要得到的是 3 ; 888#!@kf^&%4343hdslhg则要得到的是4
字符串的长度不固定.
判断字符可能比较难的话,只判断字母就好了.
多谢!

作者: clintonus   发布时间: 2011-10-03

VB code

Option Explicit

Private 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 Sub

Private Sub Form_Load()
    Text1.Text = "77kfhdslhg"
    Text2.Text = "0"
End Sub


作者: Veron_04   发布时间: 2011-10-03

VB code
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

作者: lxq19851204   发布时间: 2011-10-03

VB code
With CreateObject("vbscript.regExp")
    .Pattern = "[^\d]"
    MsgBox .Execute("77kfh434d%^&slhg")(0).firstindex + 1
End With

作者: sysdzw   发布时间: 2011-10-03

热门下载

更多