Solved

What is the simplest way to arrange a list in alphabetical order?

Posted on 2014-10-16
6
79 Views
Last Modified: 2014-11-14
Hello All,

I am trying to come up with the simplest way of accomplishing the following:

- From a list of emails, separated by comma, put them in a format that will enable me to arrange them in alphabetical order.

I was thinking about copying this list to a text file --> imported into excel as comma delimited, etc, but the user is asking me for a simpler way (by the way the user uses Excel on a MacOS).

Any ideas will be welcomed! It could be any other application or way to accomplish this, I just mentioned excel as an example.
0
Comment
Question by:LuiLui77
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
6 Comments
 
LVL 23

Expert Comment

by:Danny Child
ID: 40384890
I'd paste them into Word, not Excel, as it handles Find/Replace better.

Find ,
Replace with ^p
[^p is the Paragraph Mark, ie the same as hitting Enter.]

Then, select the whole block in Word (CTRL + A), then hit the AZ sort button on the Home tab.
0
 
LVL 23

Expert Comment

by:Danny Child
ID: 40384893
the ^ character (the "caret") is Shift +6 on my keyboard (UK), by the way...
0
 
LVL 51

Expert Comment

by:Rgonzo1971
ID: 40384894
Hi,

In Word you could replace the commas with Paragraph remark(^p)  and then sort them

Regards
0
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 34

Accepted Solution

by:
sarabande earned 500 total points
ID: 40396643
the following c++ program should convert your comma-separated file to a sorted file:

#include <string>
#include <fstream>
#include <sstream>
#include <algorithm>
#include <vector>

int main(int nargs, char * szargs[])
{
    if (nargs != 2) 
        return -1;  // no argument
    std::ifstream infile(szargs[1]);
    if (!infile) 
        return -2;  // file cannot be opened
    std::string strline;
    std::vector<std::string> strings;
    while (std::getline(infile, strline))       
    {
        std::string strmail;
        std::istringstream issline(strline);
        while (std::getline(issline, strmail, ','))
            strings.push_back(strmail+',');
    }
    infile.close();
    std::ofstream outfile(szargs[1], std::ios::trunc || std::ios::out);

    size_t nitems = strings.size();
    if (nitems > 1)
    {
        std::sort(strings.begin(), strings.end());
        for (std::vector<std::string>::iterator it = strings.begin(); it != strings.end()-1; ++it)
            strline += *it;
        strline += strings.back();
        std::ostreambuf_iterator<char> out(outfile);
        std::copy(strline.begin(), --strline.end(), out);
    }
    if (strings.empty() == false)
    {
        strline = strings.back();
        strline.resize(strline.size()-1);
        outfile << strline;
        outfile.close();
    }
    return 0; 
} 

Open in new window



use any c++ ide - for example visual studio express - and create a new empty win32 console project. then add the above source code and build.

Sara
0
 

Author Comment

by:LuiLui77
ID: 40406693
Thanks sarabande!, I will be giving this a try after building.
0
 

Author Closing Comment

by:LuiLui77
ID: 40442592
Thanks! it worked for me.
0

Featured Post

On Demand Webinar: Networking for the Cloud Era

Ready to improve network connectivity? Watch this webinar to learn how SD-WANs and a one-click instant connect tool can boost provisions, deployment, and management of your cloud connection.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Although it can be difficult to imagine, someday your child will have a career of his or her own. He or she will likely start a family, buy a home and start having their own children. So, while being a kid is still extremely important, it’s also …
When you see single cell contains number and text, and you have to get any date out of it seems like cracking our heads.
With the power of JIRA, there's an unlimited number of ways you can customize it, use it and benefit from it. With that in mind, there's bound to be things that I wasn't able to cover in this course. With this summary we'll look at some places to go…
Introduction to Processes

705 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question