Trim 一个特定的字符串

Trim a specific string

我正在操作字符串。
我希望输出字符串仅在 2 个特定字符之间(=o

我可以重复两次:

For f = 1 To Len(line5)
    If Mid(line5, f, 1) = "=" Then
        line5 = Mid(line5, f, Len(line5) - f + 1)
        line5 = line5_out
    End If

=一次,o一次

有更快的方法吗?

有多种方法可以做到,"best" 方法取决于您的具体需要。 除了这些评论之外,还有两种方法可以做到这一点:

'Delete everything behind o and infront of =
YourString = YourString.Remove(YourString.LastIndexOf("o") + 1, YourString.Length - YourString.LastIndexOf("o") - 1).Remove(0, YourString.IndexOf("="))

'Get part of string between = and o
YourString = YourString.Substring(IndexOf("="), YourString.LastIndexOf("o") + 1 - YourString.IndexOf("="))