Solved

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

Posted on 2014-10-16
6
77 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
Independent Software Vendors: 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

Industry Leaders: 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!

Question has a verified solution.

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

This article descibes how to create a connection between Excel and SAP and how to move data from Excel to SAP or the other way around.
How to get Spreadsheet Compare 2016 working with the 64 bit version of Office 2016
Many functions in Excel can make decisions. The most simple of these is the IF function: it returns a value depending on whether a condition you describe is true or false. Once you get the hang of using the IF function, you will find it easier to us…
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…

685 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