Solved

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

Posted on 2014-10-16
6
76 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 50

Expert Comment

by:Rgonzo1971
ID: 40384894
Hi,

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

Regards
0
Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

 
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

Networking for the Cloud Era

Join Microsoft and Riverbed for a discussion and demonstration of enhancements to SteelConnect:
-One-click orchestration and cloud connectivity in Azure environments
-Tight integration of SD-WAN and WAN optimization capabilities
-Scalability and resiliency equal to a data center

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
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 …
This Micro Tutorial will demonstrate in Google Sheets how to use the HYPERLINK function to create live links inside your spreadsheet.
Although Jacob Bernoulli (1654-1705) has been credited as the creator of "Binomial Distribution Table", Gottfried Leibniz (1646-1716) did his dissertation on the subject in 1666; Leibniz you may recall is the co-inventor of "Calculus" and beat Isaac…

829 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