【发布时间】:2014-04-04 13:43:01
【问题描述】:
我想从字符串中过滤掉特定的单词。 例如, “这是一个样本文件。” 要在 excel vba = "file" 中过滤掉的单词。 请帮助,急需此代码。 谢谢。
【问题讨论】:
我想从字符串中过滤掉特定的单词。 例如, “这是一个样本文件。” 要在 excel vba = "file" 中过滤掉的单词。 请帮助,急需此代码。 谢谢。
【问题讨论】:
Instr("This is a sample file.", "file") 将为您提供“文件”在较长字符串中第一次出现的位置,如果不存在则为 0。
您可以使用Left、Mid 和Right 删除字符串的元素。 Len 为您提供字符串的长度。
把所有这些放在一起:
Sub Test()
Dim s1 As String
Dim s2 As String
Dim pos As Integer
s1 = "This is a sample file."
s2 = "file"
pos = InStr(s1, s2)
If pos > 0 Then
Debug.Print Left(s1, pos - 1) & Mid(s1, pos + Len(s2))
End If
End Sub
【讨论】: