在电子邮件主题行中搜索电话号码 [英] Searching for phone numbers in email subject line

查看:140
本文介绍了在电子邮件主题行中搜索电话号码的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

http:处的示例开始: //msdn.microsoft.com/zh-CN/library/office/aa209973(v=office.11​​).aspx ,我能够创建以下代码块,用于搜索Outlook收件箱中的电子邮件主题行以"ci_startswith"开头的特定电话号码"555-5555".

Starting with the example at http://msdn.microsoft.com/en-us/library/office/aa209973(v=office.11).aspx, I was able to create the following block of code that searches the Outlook inbox for emails where the subject line starts with a specific phone number '555-5555' using "ci_startswith".

Public blnSearchComp As Boolean

Private Sub Application_AdvancedSearchComplete(ByVal SearchObject As Search)
    MsgBox "The AdvancedSearchComplete Event fired."
    blnSearchComp = True
End Sub

Sub TestAdvancedSearchComplete()
    Dim sch As Outlook.Search
    Dim rsts As Outlook.Results
    Dim i As Integer
    blnSearchComp = False
    Const strF As String = "urn:schemas:mailheader:subject ci_startswith '555-5555'"
    Const strS As String = "Inbox"   
    Set sch = Application.AdvancedSearch(strS, strF) 
    While blnSearchComp = False
        DoEvents
    Wend 
    Set rsts = sch.Results
    For i = 1 To rsts.Count
        MsgBox rsts.Item(i).SenderName
    Next
End Sub

很明显,如果主题行不是以确切的电话号码开头(在本例中为"555-5555"),则搜索找不到电子邮件.我尝试使用"like"比较代替"ci_startswith",但是现在找不到任何匹配项,包括使用"ci_startswith"找到的匹配项.

Obviously, if the subject line does not start with the exact phone number, in this case '555-5555', the search doesn't find the email. In place of "ci_startswith", I tried using the "like" comparison, however this now fails to find any matches, including those found with the "ci_startswith".

    Const strF As String = "urn:schemas:mailheader:subject like '555-5555'"

我不正确地使用喜欢"比较吗?从我阅读的内容来看,它似乎应该可以工作.还是这是已知的错误/问题?如果是这样,是否有任何变通办法可以提供更广泛的搜索功能?

Am I using the "like" comparison incorrectly? From what I've read, it appears it should work. Or is this a known bug/issue? If so, are there any workarounds that provide a broader search ability?

最终,我想使用如下所示的内容来搜索电话号码的所有可能实例.

Ultimately, I'd like to use something like below to be able to search for all possible instances of a phone number.

    Const strF As String = "urn:schemas:mailheader:subject like '###-####'"

提前谢谢!

---------编辑/添加---------

--------- EDIT / ADD ---------

Public blnSearchComp As Boolean

Private Sub Application_AdvancedSearchComplete(ByVal SearchObject As search)
    MsgBox "The AdvancedSearchComplete Event fired."
    blnSearchComp = True
End Sub

Sub TestAdvancedSearchComplete()
    Dim sch As Outlook.search
    Dim rsts As Outlook.Results
    Dim i As Integer
    blnSearchComp = False
    Const strF As String = "urn:schemas:mailheader:subject LIKE '%###%'"
    Const strS As String = "Inbox"
    Set sch = Application.AdvancedSearch(strS, strF)
    While blnSearchComp = False
        DoEvents
    Wend
    Set rsts = sch.Results
    For i = 1 To rsts.Count
        MsgBox rsts.Item(i).SenderName
    Next
End Sub

推荐答案

使用喜欢"时,您必须根据搜索条件在条件周围添加%字符

when using "LIKE" you have to add the % character around your criteria depending on how you want to search

http://msdn.microsoft .com/en-us/library/office/cc513841(v = office.12).aspx

诸如之类的关键字执行前缀,子字符串或等效项匹配.根据匹配的类型,标记(字符,单词或单词)以特定的方式用%字符括起来:像'%'提供前缀匹配.例如,限制"cat%"之类的内容将匹配"cat"和"catalog".如'%%'提供子字符串匹配.例如,限制为'%cat%'会匹配"cat","catalog","kittycat"和十项全能".像''提供了等效匹配.例如,限制"cat"之类的内容将匹配"cat"和"RE:Cat".

The keyword like performs prefix, substring, or equivalence matching. Tokens (characters, word, or words) are enclosed with the % character in a specific way depending on the type of matching: like '%' provides prefix matching. For example, restricting for like 'cat%' would match "cat" and "catalog." like '%%' provides substring matching. For example, restricting for like '%cat%' would match "cat," "catalog," "kittycat," and "decathlon." like '' provides equivalence matching. For example, restricting for like 'cat' would match "cat" and "RE: Cat."

这篇关于在电子邮件主题行中搜索电话号码的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆