我有输入“Nokia S40 Browser 2.2.0”,我想删除版本号。输出应为“Nokia S40 Browser”。换句话说,我想从我的输入中删除2.2.0。我怎么能这样做?
答案 0 :(得分:2)
如果版本号始终是文本的最后一部分,那么您可以使用
=TRIM(RIGHT(SUBSTITUTE(A1," ",REPT(" ",100)),100))
获取最后一部分和
=SUBSTITUTE(A1,TRIM(RIGHT(SUBSTITUTE(A1," ",REPT(" ",100)),100)),"")
删除文本的最后部分。
或者您可以使用RegEx删除版本号
Function remomveVers(Myrange As Range) As String
'Dim regEx As New regEx
Set regEx = CreateObject("VBScript.RegExp")
Dim strPattern As String
Dim strInput As String
Dim strReplace As String
Dim strOutput As String
strPattern = "([0-9]{1,2}[.][0-9]{1,2}[.][0-9]{1,2})|([0-9]{1,2}[.][0-9]{1,2})"
If strPattern <> "" Then
strInput = Myrange.Value
strReplace = ""
With regEx
.Global = True
.MultiLine = True
.IgnoreCase = False
.Pattern = strPattern
End With
If regEx.test(strInput) Then
remomveVers = regEx.Replace(strInput, strReplace)
Else
remomveVers = "Not matched"
End If
End If
End Function
您可以在工作表上使用此功能(参见下面的屏幕截图)