【发布时间】:2018-11-18 18:05:12
【问题描述】:
我有一个用 C# 编写的 Outlook 插件,它可以扫描电子邮件,并将它们随机排列到不同的文件夹中。因为我们搜索的术语变化频繁,以至于将它们作为变量添加到程序中是完全不可接受的;最重要的是,列表很长! 我这样做是为了让代码从 CSV 中提取行并在 DASL 查询中使用该术语。
我的问题是,当我们需要搜索诸如“don't”、“haven't”、“shan't”、“Dave's”之类的词时,其他收缩或所有格名词会导致问题。我已经尝试了我能想到的一切来改善这个问题,不幸的是我不知所措。除非引入收缩,否则该程序可以完美运行。请帮忙:)
最相关的代码块是这样的:
using (StreamReader r = new StreamReader(fileLoc))
{
//while != null to kill the loop
string line;
string prefix = @"@SQL=urn:schemas:httpmail:textdescription like '";
string postfix = @"'";
while ((line = r.ReadLine()) != null)
{
//slurp the csv line out, and spit it into DASL query.
line = prefix + line + postfix;
lines.Add(line);
}
} //closes out the streamreader object?
string[] outputArray = lines.ToArray();
return outputArray;
我的 CSV 文件如下所示:
%i do not%
%i flipped it%
%no thanks%
当我尝试添加 %don't do that% 或 %won't% 之类的内容时,我会遇到问题。
遗憾的是,我尝试过 %don't%、%"don't"%、%don/'t%、%dochr(39)t% 之类的方法,但均未成功。
如何使 DASL 查询使用撇号?而且,当它存在于 CSV 文件的记录中时,如何让它接受该撇号?
谢谢:)
编辑 这是我用来搜索带有 DASL 查询的电子邮件的模块,如果它可以帮助某人确定问题。
public void SearchEmailBodyWithArray(string[] filter)
{
//this is the workhorse of this program
MessageBox.Show("Pick Source Folder");
Outlook.MAPIFolder olFolder = Application.Session.PickFolder();
MessageBox.Show("Pick Destination Folder");
Outlook.MAPIFolder destFolder = Application.Session.PickFolder();
Outlook.Items items = olFolder.Items;
Outlook.MailItem mailItem = null;
object folderItem;
string subjectName = string.Empty;
int f = 0;
while ( f < filter.Length)
{
folderItem = items.Find(filter[f]);
while (folderItem != null)
{
mailItem = folderItem as Outlook.MailItem;
if (mailItem != null)
{
subjectName += "\n" + mailItem.Subject;
mailItem.Move(destFolder);
}
folderItem = items.FindNext();
}
f++;
}
subjectName = " The following e-mail messages were found: " +
subjectName;
MessageBox.Show(subjectName);
}
【问题讨论】:
标签: c# visual-studio outlook-addin apostrophe