Java

本类阅读TOP10

·使用MyEclipse开发Struts框架的Hello World!(录像1)
·hibernate配置笔记
·AOP编程入门--Java篇
·linux下Tomcat 5.0.20 与 Apache 2 安装/集成/配置
·在win2003下整合了整合Tomcat5.5+ apache_2.0.53+ mod_jk_2.0.47.dll
·构建Linux下IDE环境--Eclipse篇
·Jsp 连接 mySQL、Oracle 数据库备忘(Windows平台)
·ASP、JSP、PHP 三种技术比较
·Tomcat5.5.9的安装配置
·AWT GUI 设计笔记(二)

分类导航
VC语言Delphi
VB语言ASP
PerlJava
Script数据库
其他语言游戏开发
文件格式网站制作
软件工程.NET开发
从outlook导入email地址

作者:未知 来源:月光软件站 加入时间:2005-2-28 月光软件站

outlook有一种email地址格式,采用逗号分隔开字段,扩展名叫CSV。
例如:
"姓名","称谓","单位名称","部门","职务","邮政地址","邮政编码","电话","传真","统一编码","其他电话","单位其他","移动电话","呼机","主页","电子邮件","备注"

程序打开文件,每行读取
只用第一个逗号前的字符串作为姓名,email地址匹配格式取第一个(位置无关)
于是写下粗陋程序:
 private static final String repmail ="([\\w.-]+[@]{1}((\\w)+[.]){1,3}(\\w)+)";
 private static final String repname =".+?,";
 Pattern mailPattern = Pattern.compile(repmail );
  Pattern namePattern = Pattern.compile(repname);


  File file = new File("test.CSV");
  FileInputStream is = new FileInputStream(file);
  BufferedReader br = new BufferedReader(new InputStreamReader(is));
        String input = null;
  ArrayList list = new ArrayList();
   while((input = br.readLine())!=null){
    Matcher matchermail = mailPattern.matcher(input);
    Matcher matchername = namePattern.matcher(input);
    String[] card = new String[2];
    if(matchername.find()){
      card[0] = matchername.group(0).replaceAll("\"","");
    }
       if(matchermail.find()){
         card[1] = matchermail.group(0);
    }
    if(card[0]==null || card[0].equals("") || card[1]==null || card[1].equals("")){
      continue;
    }
    list.add(card);
  }
//输出
  for(int i=0;i<list.size();i++){
          System.out.println(((String[])list.get(i))[0] + ":" + ((String[])list.get(i))[1]);
  }

 




相关文章

相关软件