删除数字和的组合。 从Excel中的string
我有input“诺基亚S40浏览器2.2.0”从这个我想删除版本号。 输出应该是“诺基亚S40浏览器”。 换句话说,我想从我的input中删除2.2.0。 我怎样才能做到这一点?
如果版本号总是文本的最后部分,那么你可以使用
=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
你可以在你的工作表上使用这个function(见下面的截图)