Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 115257
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 11, 20262026-05-11T02:59:26+00:00 2026-05-11T02:59:26+00:00

So i am working with some email header data, and for the to:, from:,

  • 0

So i am working with some email header data, and for the to:, from:, cc:, and bcc: fields the email address(es) can be expressed in a number of different ways:

First Last <name@domain.com> Last, First <name@domain.com> name@domain.com 

And these variations can appear in the same message, in any order, all in one comma separated string:

First, Last <name@domain.com>, name@domain.com, First Last <name@domain.com> 

I’ve been trying to come up with a way to parse this string into separate First Name, Last Name, E-Mail for each person (omitting the name if only an email address is provided).

Can someone suggest the best way to do this?

I’ve tried to Split on the commas, which would work except in the second example where the last name is placed first. I suppose this method could work, if after i split, i examine each element and see if it contains a ‘@’ or ‘<‘/’>’, if it doesn’t then it could be assumed that the next element is the first name. Is this a good way to approach this? Have i overlooked another format the address could be in?


UPDATE: Perhaps i should clarify a little, basically all i am looking to do is break up the string containing the multiple addresses into individual strings containing the address in whatever format it was sent in. I have my own methods for validating and extracting the information from an address, it was just tricky for me to figure out the best way to separate each address.

Here is the solution i came up with to accomplish this:

String str = 'Last, First <name@domain.com>, name@domain.com, First Last <name@domain.com>, \'First Last\' <name@domain.com>';  List<string> addresses = new List<string>(); int atIdx = 0; int commaIdx = 0; int lastComma = 0; for (int c = 0; c < str.Length; c++) {     if (str[c] == '@')         atIdx = c;      if (str[c] == ',')         commaIdx = c;      if (commaIdx > atIdx && atIdx > 0)     {         string temp = str.Substring(lastComma, commaIdx - lastComma);         addresses.Add(temp);         lastComma = commaIdx;         atIdx = commaIdx;     }      if (c == str.Length -1)     {         string temp = str.Substring(lastComma, str.Legth - lastComma);         addresses.Add(temp);     } }  if (commaIdx < 2) {     // if we get here we can assume either there was no comma, or there was only one comma as part of the last, first combo     addresses.Add(str); } 

The above code generates the individual addresses that i can process further down the line.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. 2026-05-11T02:59:27+00:00Added an answer on May 11, 2026 at 2:59 am

    Here is the solution i came up with to accomplish this:

    String str = 'Last, First <name@domain.com>, name@domain.com, First Last <name@domain.com>, \'First Last\' <name@domain.com>';  List<string> addresses = new List<string>(); int atIdx = 0; int commaIdx = 0; int lastComma = 0; for (int c = 0; c < str.Length; c++) { if (str[c] == '@')     atIdx = c;  if (str[c] == ',')     commaIdx = c;  if (commaIdx > atIdx && atIdx > 0) {     string temp = str.Substring(lastComma, commaIdx - lastComma);     addresses.Add(temp);     lastComma = commaIdx;     atIdx = commaIdx; }  if (c == str.Length -1) {     string temp = str.Substring(lastComma, str.Legth - lastComma);     addresses.Add(temp); } }  if (commaIdx < 2) {     // if we get here we can assume either there was no comma, or there was only one comma as part of the last, first combo     addresses.Add(str); } 
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Ask A Question

Stats

  • Questions 113k
  • Answers 113k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer This problem of "losing the type" can be solved with… May 11, 2026 at 10:02 pm
  • Editorial Team
    Editorial Team added an answer I used Tanimoto Coefficient for a quick (but not super)… May 11, 2026 at 10:02 pm
  • Editorial Team
    Editorial Team added an answer It's been a while now with no takers, so I'm… May 11, 2026 at 10:02 pm

Related Questions

I'm an email n00b but I am working on an application that sends HTML
I need to make a large set of tests in telnet. I am working
My company is a custom development shop for a number of projects, some larger
Aparently, encoding japanese emails is somewhat challenging, which I am slowly discovering myself. In

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.