Solved

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

Posted on 2014-10-16
6
70 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:DanCh99
Comment Utility
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:DanCh99
Comment Utility
the ^ character (the "caret") is Shift +6 on my keyboard (UK), by the way...
0
 
LVL 48

Expert Comment

by:Rgonzo1971
Comment Utility
Hi,

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

Regards
0
Highfive + Dolby Voice = No More Audio Complaints!

Poor audio quality is one of the top reasons people don’t use video conferencing. Get the crispest, clearest audio powered by Dolby Voice in every meeting. Highfive and Dolby Voice deliver the best video conferencing and audio experience for every meeting and every room.

 
LVL 32

Accepted Solution

by:
sarabande earned 500 total points
Comment Utility
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
Comment Utility
Thanks sarabande!, I will be giving this a try after building.
0
 

Author Closing Comment

by:LuiLui77
Comment Utility
Thanks! it worked for me.
0

Featured Post

How to improve team productivity

Quip adds documents, spreadsheets, and tasklists to your Slack experience
- Elevate ideas to Quip docs
- Share Quip docs in Slack
- Get notified of changes to your docs
- Available on iOS/Android/Desktop/Web
- Online/Offline

Join & Write a Comment

A short article about a problem I had getting the GPS LocationListener working.
If you’re thinking to yourself “That description sounds a lot like two people doing the work that one could accomplish,” you’re not alone.
The viewer will learn how to create a normally distributed random variable in Excel, use a normal distribution to simulate the return on an investment over a period of years, Create a Monte Carlo simulation using a normal random variable, and calcul…
This Micro Tutorial will demonstrate in Microsoft Excel how to add style and sexy appeal to horizontal bar charts.

762 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

Need Help in Real-Time?

Connect with top rated Experts

8 Experts available now in Live!

Get 1:1 Help Now