- 发帖
- 10085
- 财富
- 62933
- 威望
- 2083
- 交易币
- 62
|
自写,备份一下,方便以后使用。 - Public Function CutString(ByVal str As String, ByVal str1 As String, ByVal str2 As String, ByVal str1_ok As Boolean, ByVal str2_ok As Boolean) As String
- '参数说明
- 'str1——母串,str1——开始截取的子串,str2——结束截取的子串,str1_ok——是否保留str1,str2_ok——是否保留str2
- Dim m As Integer
- Dim n As Integer
-
- On Error Resume Next
-
- m = InStr(1, str, str1, vbTextCompare)
- n = InStr(1, str, str2, vbTextCompare)
-
- If str1_ok = True Then '保留开始截取的子串[
- If str2_ok = False Then
- CutString = Mid(str, m, n - m) '不保留结束子串[)
- Else
- CutString = Mid(str, m, n - m + Len(str2)) '保留结束子串[]
- End If
- Else '不保留开始子串(
- If str2_ok = False Then
- CutString = Mid(str, m + Len(str1), n - m - Len(str1)) '不保留结束子串()
- Else
- CutString = Mid(str, m + Len(str1), n - m - Len(str1) + Len(str2)) '保留结束子串(]
- End If
- End If
- End Function
|