Solved

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

Posted on 2014-10-16
6
75 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
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 49

Expert Comment

by:Rgonzo1971
ID: 40384894
Hi,

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

Regards
0
Gigs: Get Your Project Delivered by an Expert

Select from freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely and get projects done right.

 
LVL 33

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

Gigs: Get Your Project Delivered by an Expert

Select from freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely and get projects done right.

Question has a verified solution.

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

A short article about problems I had with the new location API and permissions in Marshmallow
This article will inform Clients about common and important expectations from the freelancers (Experts) who are looking at your Gig.
Graphs within dashboards are meant to be dynamic, representing data from a period of time that will change each time the dashboard is updated with new data. Rather than update each graph to point to a different set within a static set of data, t…
This Micro Tutorial will demonstrate the scrolling table in Microsoft Excel using the INDEX function.

785 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