有一个url.txt 里面保存了很多网址如:http://www.xxx.com/***/**.html
http://www.xxx.com/**.html
http://www.xxx.com/**/xxxx/xxx/xx.php 等想用c# 写一个控制台程序提取其中的域名最后生成一个这样格式的www.xxx.com 文本文档希望提供演示代码!

解决方案 »

  1.   

    测试文本内容
    http://www.baidu.com/***/**.html
    http://www.sina.com.cn//**.html
    http://www.sohu.com//**/xxxx/xxx/xx.php 代码处理string[] yuming_array=File.ReadAllLines(@"C:\Documents and Settings\Administrator\桌面\Test.txt", Encoding.GetEncoding("GB2312")).Select(a => { return Regex.Match(a, @"(?<=http://)[\w\.]+[^/]").Value; }).ToArray();//读取并筛选符合条件的域名
                    File.WriteAllLines(@"C:\Documents and Settings\Administrator\桌面\Test.txt",yuming_array);//写入文档
    结果
    www.baidu.com
    www.sina.com.cn
    www.sohu.com