在vb中text1中有"...tasdldjffhhkkghfgy...(表示很多字符)".

来源:百度知道 编辑:UC知道 时间:2024/06/16 23:07:23
我要从s开始的两个字符,还需要d(第一个)和h(第二个)中间的字符。怎么写代码呢?

Private Sub Command1_Click()
Dim a As Long, b As Long, nStr As String

'得到以S开头的两个字符:
a = InStr(Text1.Text, "s")
If a > 0 Then
nStr = Mid(Text1.Text, 2)
MsgBox "以S开头的两个字符=" & nStr
End If

'得到d和h之间的字符:
a = InStr(Text1.Text, "d")
b = InStr(a + 1, Text1.Text, "h")
If a > 0 And b > 0 Then
nStr = Mid(Text1.Text, a + 1, b - a - 1)
MsgBox "d和h之间的字符=" & nStr
End If
End Sub