只用正则: 判断字符串中是否有"abc" 有则去掉之 using System.Text.RegularExpressions; string str = "123abc456"; string a="abc"; Regex r = new Regex(a); Match m = r.Match(str); if (m.Success) { str=str.Replace(a,""); Response.Write(str); }
string s = "{Subject}尊敬的lvzhou您好"; int i = s.IndexOf("}"); s = s.Substring(i+1, s.Length - i-1);
判断字符串中是否有"abc" 有则去掉之
using System.Text.RegularExpressions;
string str = "123abc456";
string a="abc";
Regex r = new Regex(a);
Match m = r.Match(str);
if (m.Success)
{
str=str.Replace(a,"");
Response.Write(str);
}
string s = "{Subject}尊敬的lvzhou您好";
int i = s.IndexOf("}");
s = s.Substring(i+1, s.Length - i-1);
void Main()
{
string str2=@"{Subject}尊敬的lvzhou您好,您在网客户服务平台的会员注册信息,请查收。{/Subject}尊敬用你你好...........";
str2=Regex.Replace(str2,"{Subject}((?!{/?Subject}).)*?{/Subject}","");
Console.WriteLine(str2); //尊敬用你你好...........
}