Splitting text with regular expressions

D

David Jackson

Hello,

The company I'm working for has taken over a smaller company with a fairly
large customer base. We want to send an email to that customer base
informing them of the takeover but the mailing list is not held in a
database. In fact we've been given it as a Word document.

The individual email addresses are in the format: "Name <address>" e.g.

Bill Gates <[email protected]>;

and I've been tasked with the job of splitting the data into its constituent
parts so that we can store them separately in our database.

I wondered if regular expressions might be the most efficient way of doing
this?

Can anyone help me with some guidance on how I might do this?

Thanks,

DJ
 
B

bob clegg

Hi David,
If you stay in the Word format you will using the Word interop DLL to
move around and capture chunks of text.
Once you have captured a string it doesn't matter much whether you use
regex or string functions to break the string into email address and
name. IMHO.
I prefer regex but am not an expert and rely heavily on Regex Buddy to
construct the expressions.
Given this job is a once only and I dare say you are under a bit of
pressure to get this finished my gut reaction is to get the data into
a csv file if possible. (Word Table -> Excel -> CSV ) then you can
read it line by line and use string functions to break it up prior to
writing to your database.
hth
Bob
 
D

David Jackson

Hi Bob,

Thanks for the reply.
If you stay in the Word format you will using the Word interop DLL to
move around and capture chunks of text.

No intention to stay in the Word format.
I prefer regex but am not an expert and rely heavily on Regex Buddy to
construct the expressions.

OK, I'll have a look at that for the future.
Given this job is a once only and I dare say you are under a bit of
pressure to get this finished my gut reaction is to get the data into
a csv file if possible. (Word Table -> Excel -> CSV ) then you can
read it line by line and use string functions to break it up prior to
writing to your database.

In fact, a colleague suggested a much better alternative for this:

string strRawEmail = "Bill Gates <[email protected]>";
MailAddress objMailAddress = new MailAddress(strRawEmail);
string strEmailAddress = objMailAddress.Address;
string strDisplayName = objMailAddress.DisplayName;

DJ
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top