我正在尝试为一个类(class)项目构建一个网络钓鱼扫描器,但我一直在尝试将电子邮件保存在文本文件中以正确复制到数组中以供以后处理。我想要的是每个单词都在它自己的数组索引中。
这是我的示例电子邮件:
Subject: Insufficient Funds Notice
Date: September 25, 2013
Insufficient Funds Notice
Unfortunately, on 09/25/2013 your available balance in your Wells Fargo account XXXXXX4653 was insufficient to cover one or more of your checks, Debit Card purchases, or other transactions.
An important notice regarding one or more of your payments is now available in your Messages & Alerts inbox.
To read the message, click here, and first confirm your identity.
Please make deposits to cover your payments, fees, and any other withdrawals or transactions you have initiated. If you have already taken care of this, please disregard this notice.
We appreciate your business and thank you for your prompt attention to this matter.
If you have questions after reading the notice in your inbox, please refer to the contact information in the notice. Please do not reply to this automated email.
Sincerely,
Wells Fargo Online Customer Service
wellsfargo.com | Fraud Information Center
4f57e44c-5d00-4673-8eae-9123909604b6
我不需要任何标点符号,我只需要单词和数字。
这是我到目前为止为它编写的代码。
StreamReader sr1 = new StreamReader(lblDisplaySelectedFilePath.Text);
string line = sr1.ReadToEnd();
words = line.Split(' ');
int wordslowercount = 0;
foreach (string word in words)
{
words[wordslowercount] = word.ToLower();
wordslowercount = wordslowercount + 1;
}
上述代码的问题在于,我不断收到在数组中串在一起和/或上面有“\r”或“\n”的单词。这是数组中我不想要的内容的示例。
"notice\r\ndate:" 不想要\r、\n 或 :。此外,这两个词应该在不同的索引中。
请您参考如下方法:
正则表达式 \W 将允许您拆分字符串并创建单词列表。这使用单词边界,因此不会包含标点符号。
Regex.Split(inputString, "\\W").Where(x => !string.IsNullOrWhiteSpace(x));
