public String GetEMailAddresses(string Input)
{
System.Text.RegularExpressions.MatchCollection MC = System.Text.RegularExpressions.Regex.Matches(Input, "\\w+([-+.']\\w+)*@\\w+([-.]\\w+)*\\.\\w+([-.]\\w+)*");
if(MC.Count > 0)
return MC[0].Value;
return "";
}
您可以使用上述方法找到電子郵件地址。如果它返回的東西不是「」,這意味着它是一個電子郵件地址。現在,你可以簡單地使用方法與string.replace與新的電子郵件地址,以取代舊
string input = "Hi, My name is John Martin. I am a painter and sculptor. If you wish to purchase my paintings please look at my portfolio on the site and then contact me on [email protected]";
string email = GetEMailAddresses(input);
input = input.Replace(email, "[email protected]");
它總是'john @ gmail.com'? –
不..也可以是[email protected] .. :-) –