标记字符串

发布于 2024-07-26 21:54:50 字数 189 浏览 8 评论 0原文

我有大约 100 行想要标记的文本,它们类似于以下内容:

<word> <unknown number of spaces and tabs> <number>

我在使用 VBA 查找标记化函数时遇到问题。 在 VBA 中标记此类字符串的最简单方法是什么?

I have around 100 rows of text that I want to tokenize, which are alike the following:

<word> <unknown number of spaces and tabs> <number>

I am having trouble finding tokenize functions with VBA. What would be the easiest method to tokenize such strings in VBA?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

脸赞 2024-08-02 21:54:51

您可以使用 Split() 方法,或者对于更复杂的匹配,您可以使用 "vbscript.regexp" 对象:

Sub NewRegex()
    Dim reg
    Dim matches, match, tmpStr As String

    Set reg = CreateObject("vbscript.regexp")
    tmpStr = "blah bla ...."

    With reg
        .IgnoreCase = True
        .MultiLine = False
        .Pattern = "your regex pattern goes here"
        .Global = True
    End With

    Set matches = reg.Execute(tmpStr)

    For Each match In matches
        MsgBox match
    Next mt

End Sub

以下是有关在 VBA 中使用正则表达式的教程:在 Excel 中使用正则表达式 (RegExp)

You can use the Split() method or for more complex matches, you can use the "vbscript.regexp" object:

Sub NewRegex()
    Dim reg
    Dim matches, match, tmpStr As String

    Set reg = CreateObject("vbscript.regexp")
    tmpStr = "blah bla ...."

    With reg
        .IgnoreCase = True
        .MultiLine = False
        .Pattern = "your regex pattern goes here"
        .Global = True
    End With

    Set matches = reg.Execute(tmpStr)

    For Each match In matches
        MsgBox match
    Next mt

End Sub

Here's a tutorial on using regex from VBA: Using Regular Expressions (RegExp) in Excel

另类 2024-08-02 21:54:51

您可以逐行阅读并使用 split 函数按空格分割单词和数字。 我依稀记得VBA有split功能。

我通过谷歌搜索得到了以下链接。 不确定您使用的是哪个版本的 Office。

http://msdn.microsoft.com/en-us /library/aa155763(office.10).aspx

该链接具有分割功能。

You could read line by line and use the split function to split the word and number by space. I vaguely remeber VBA has the split function.

I got the following link by searching in google. Not sure which version of office you are using.

http://msdn.microsoft.com/en-us/library/aa155763(office.10).aspx

This link has the split function.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文