string - Excel VBA - 删除最多*单词*的字符串内容

标签 string vba excel

我正在尝试删除字符串内容,直至字符串中包含的某个单词。例如

"Emily has wild flowers. They are red and blue."

我想使用 VBA 来替换它

"They are red and blue."

即删除“他们”一词之前的所有内容。我不知道字符串内容以及其中包含的字符数。

我不知道如何执行此操作,非常感谢您的帮助!

最佳答案

给你:

Dim s As String
s = "Emily has wild flowers. They are red and blue."

Dim indexOfThey As Integer

indexOfThey = InStr(1, s, "They")


Dim finalString As String
finalString = Right(s, Len(s) - indexOfThey + 1)

关于string - Excel VBA - 删除最多*单词*的字符串内容,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18402931/

相关文章:

excel - "Object doesn' t 支持此操作"用于 Excel 2011 (Mac OS X) 中的下拉菜单

python - 计算行数并对其编号

vba - 当电子表格中出现错误时,如何停止触发基于事件的 VBA 代码?

vba - 两个字符串不会连接 VBA Excel

excel - 使用宏对表格进行排序

vba - 自动化错误: The object invoked has disconnected from its clients

vba - 使用 IFF 语句将 SQL 查询写入 VBA,出现缺少表达式错误

java - 为什么这不抛出异常?

php - 从 PHP 数组中提取字符串

java - 无法编译我的代码