需求:
在字符串“http://123.com.cn www.yetd.cn http://123.aaa.com 456.aaa.com http://999.bbb.com”中去掉包含aaa.com关键字的字符串,去除后的结果应为:“http://123.com.cn www.yetd.cn http://999.bbb.com”,注意每个url地址中间都有一个空格(只能有一个)作为分隔符。这似乎需要用上正则表达式,可我在这方面基础实在太差,时间又很紧,已经来不及仔细学习了,只好烦请各位高手多多指点一下,谢谢!
在字符串“http://123.com.cn www.yetd.cn http://123.aaa.com 456.aaa.com http://999.bbb.com”中去掉包含aaa.com关键字的字符串,去除后的结果应为:“http://123.com.cn www.yetd.cn http://999.bbb.com”,注意每个url地址中间都有一个空格(只能有一个)作为分隔符。这似乎需要用上正则表达式,可我在这方面基础实在太差,时间又很紧,已经来不及仔细学习了,只好烦请各位高手多多指点一下,谢谢!
赶紧给你写,也请你赶紧结贴
string input = "http://123.com.cn www.yetd.cn http://123.aaa.com 456.aaa.com http://999.bbb.com";
string pattern = @"\S*aaa\.com\S* ?";
MessageBox.Show(Regex.Replace(input, pattern, ""));
string s = "http://123.com.cn www.yetd.cn http://123.aaa.com 456.aaa.com http://999.bbb.com";
string[] strArr = s.Split(' ');
string strResult=""; for (int i = 0; i < strArr.Length; i++)
{
if (strArr[i].IndexOf("aaa.com") > 0)
strArr[i] = "";
if(strArr[i]!="")
strResult +=strArr[i]+" ";
}
strResult = strResult.Trim();
Console.Write(strResult);
Console.Read();
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Text.RegularExpressions;
using System.Runtime.InteropServices.ComTypes;
using System.IO;
using System.Windows.Forms;
namespace ConsoleApplication1
{
class Test
{
static void Main()
{
string str = "http://123.com.cn www.yetd.cn http://123.aaa.com 456.aaa.com http://999.bbb.com";
Regex re = new Regex(@"\S*aaa.com\S*");
Console.WriteLine(re.Replace(str,""));
}
}
}