Hi all,
I'm useless at regex, but for the task I'm currently working on it seems like the correct approach. I have a Windows Service (.NET 2.0) which needs to filter e-mail addresses.
It will receive input in a format like these:
library1@domain.com
library2@domain.dk
library3@subdomain.domain.com
etc..
What i need to do is format them into this:
library1.domain@predefined-domain.dk
library2.domain@predefined-domain.dk
library3.subdomain.domain@predefined-domain.dk
If anyone can point (or throw) me in the right direction I'd appreciate it :)
EDIT: I came up with this:
public static string FormatEmail(string inputAddress, string newDomain)
{
string result = inputAddress.Replace("@", ".");
foreach (string domain in topleveldomains)
{
if (result.LastIndexOf(domain) == result.Length - domain.Length)
{
result = result.Substring(0, result.LastIndexOf(domain));
result += "@" + newDomain;
break;
}
}
return result;
}

1 answers
Well, you could use regex but, if I've understood the pattern correctly, I think you'll find it easier and quicker to use ordinary string parsing here:
answered 4 months ago by:
12813
2135
That's somewhat simpler than the solution I came up with. They both seem to produce the same result though :) Thanks a bunch