当前位置: 移动技术网 > IT编程>开发语言>.net > .NET读取所有目录下文件正则匹配文本电子邮件

.NET读取所有目录下文件正则匹配文本电子邮件

2018年04月19日  | 移动技术网IT编程  | 我要评论

win10镜像,aeok,艺术字体库下载

复制代码 代码如下:

using system;
using system.collections.generic;
using system.text;
using system.io;
using system.text.regularexpressions;
namespace test
{
class fiemail
{
public static void main(string[] args) {
console.writeline("请输入内容路径:");
string[] fs=directory.getfiles(args[0]);
if(fs!=null){
string jobspattern=@"([\w-]+(\.\w+)*@([\w-]+\.)+\w{2,3})";
regex rx = new regex(jobspattern,regexoptions.compiled | regexoptions.ignorecase | regexoptions.multiline );
foreach(string s in fs){
console.writeline("匹配");
string asr=file.readalltext(s);
matchcollection matches = rx.matches(asr);
if(matches!=null && matches.count>0) {
string argsp="";
for(int loopi=0;loopi<matches.count;loopi++){
argsp+=(matches[loopi].groups[0].value)+environment.newline ;
}
w(argsp.trim(new char[]{'\n'}));
}
console.writeline(s);
}
}
console.readline();
}
public static void w(string ids){
string paths=system.io.path.combine(@"c:\documents and settings\administrator\桌面\gc\","edel.txt");
using (system.io.streamwriter sr = new system.io.streamwriter(paths,true)){
sr.writeline(ids);
}
}
}
}

然后csc编译,生成f.exe文件。然后就可以使用了。
里面牵扯到的技术要点:
1: c# 读取文件夹下所有文件
2:c# 利用正则获取文件中的邮址
3:c#文件写入。
完毕。

如对本文有疑问,请在下面进行留言讨论,广大热心网友会与你互动!! 点击进行留言回复

相关文章:

验证码:
移动技术网