首 页 行业热点 新车 试驾评测 养车用车 车型库

VB 从右边截取字符串

发布网友

我来回答

5个回答

热心网友

VB 从右边截取字符串可以使用Right函数:

Private Sub Command1_Click()

  s = "12345670"

  s1 = Right(s, 4)

  Print s; "的右边4个字符是"; s1

End Sub

热心网友

InStr 函数,返回指定字符在字符串中出现的第一个位置
InStrL 函数,返回指定字符在字符串中出现的最后一个位置,注:该函数自己写的,具体如下:
'取得指定字符串在原字符串中的最后的位置

Public Function InStrL(inString As String, srchString As String) As Integer

Dim iLastPos As Integer

If Len(srchString) Then

Dim iCurPos As Integer
Do
iLastPos = iCurPos
iCurPos = InStr(iCurPos + 1, inString, srchString, vbTextCompare)

Loop Until iCurPos = 0
End If

InStrL = iLastPos

End Function
然后使用Mid函数

比如wwwwwwwrrrfffffffffffffffffffeee 要截取fffffffffffffffffff
StrTest="wwwwwwwrrrfffffffffffffffffffeee"
Mid(StrTest,InStr(StrTest,"f"),InStrL(StrTest,"f")-InStr(StrTest,"f")+1)

这样就可以得到你要的字符了

热心网友

Dim str, index As String str = ".200905/2009/1232131231mjch[2009]59fj.zip" index = InStrRev(str, "/") + 1 MsgBox Mid(str, index) 注: 返回某字符串在另一个字符串中出现的从结尾计起的位置。 InStrRev(string1, string2[, start[, compare]]) 参数 string1 必选项。接受搜索的字符串表达式。 string2 必选项。被搜索的字符串表达式。 Start 可选项。数值表达式,用于设置每次搜索的开始位置。如果省略,则默认值为 -1,表示从最后一个字符的位置开始搜索。如果 start 包含 Null,则出现错误 compare 可选项。在计算子字符串时,指示要使用的比较类型的数值。如果省略,将执行二进制比较。有关数值,请参阅“设置”部分。

满意请采纳

热心网友

Private Sub Command1_Click()
'如果是数字有很多种方法可以实现
a = "88888888.999"
b = Left(a, InStr(a, ".") - 1) '第一种方法
c = Split(a, ".")(0) '第二种方法
d = CStr(Int(a)) '第三种方法
Print b
Print c
Print d

'你说的如果是字符串
a = "wwwwwwwrrr"
b = "fffffffffffffffffffeee"
a1 = Left(a, 1)
b1 = Left(b, 1)
c = ""
d = ""
For i = 1 To Len(a)
If Mid(a, i, 1) = a1 Then
c = c & Mid(a, i, 1)
Else
Exit For
End If
Next

For i = 1 To Len(b)
If Mid(b, i, 1) = b1 Then
d = d & Mid(b, i, 1)
Else
Exit For
End If
Next

Print c, d
End Sub

热心网友

Function 取整(byval 数字) as Integer
取整=cstr(fix(val(数字)))
End Function

dim a,b
a=取整(88888888.999)
b=取整(7777777777777.666)

fix介绍:
1.vb
返回一个数的整数部分
Return the integer portion of a number.
2.c++
ByVal Number As { Double | Integer | Long | Object | Short | Single | Decimal }) _
As { Double | Integer | Long | Object | Short | Single | Decimal }
Public Shared Function Fix( _
ByVal Number As { Double | Integer | Long | Object | Short | Single | Decimal }) _
As { Double | Integer | Long | Object | Short | Single | Decimal }

声明声明:本网页内容为用户发布,旨在传播知识,不代表本网认同其观点,若有侵权等问题请及时与本网联系,我们将在第一时间删除处理。E-MAIL:11247931@qq.com