我试图删除字符串的结尾部分,其中的开头和结尾是可变的,但有几个指示符。我正在使用的字符串是";编号1_xc_min_20201229_112401.rdf"。
Num1是可变的,20201229_112401是可变的(因为它是一个日期(。Num1不会总是有四个字符。我想要的最终结果是";Num1">xc总是常数。
这是我正在使用的代码:
Sub Macro1()
Dim input1 As String
Dim remove1 As String
Dim result1 As String
input1 = Range("C2").Value
remove1 = "_xc_*" 'this is the char to be removed
result1 = Replace(input1, LCase(remove1), "")
Range("C2").Value = result1
End Sub
这不起作用,因为您无法将变量设置为等于like语句。
按remove1
值拆分并返回第一个(第0个(元素:
Sub Macro1()
Dim input1 As String
Dim remove1 As String
input1 = "Num1_xc_min_20201229_112401.rdf"
remove1 = "_xc_"
Debug.Print Split(input1, remove1)(0)
End Sub
返回Num1
。