PDA

View Full Version : Sorting a list



Geoff
06-02-2014, 03:12 AM
I have a project which offers up a list of names from which the user can select one for inclusion in a paragraph of text.

The names are displayed in a comb-box. If the name the user wants isn't there, he can type a new one. He is then offered the chance to save it so that it will be there the next time.

The names are saved out to a simple data file.

When the names are read in to populate the combo box, I want them to be sorted on the surname.

The problem is picking out the surname!

A sample (short) list would be:

Mr. Dingle JP
District Judge Freda Bloggs
District Judge Edwards
District Judge Fred Bloggs OBE
His Honour Judge Williams QC
Mrs. Dingle
Mr. Christopher Snuff-Bowlstrother JP TD
Miss Marjorie Dingle JP

I don't want to make the user enter the surname as a separate item if I can help it, but I am not sure that I can help it.

So far, all I can think of is testing each string for spaces (starting at the end and working backwards). Then check the captured substring for discards (TD, JP, OBE etc) and keep checking backwards until the text has something in it other than a two to three letter discard.

I am open to better suggestions!

TIA

Geoff

snb
06-03-2014, 04:06 AM
In the absence of regularity an algorithm that assumes regularity won't be available.

Geoff
06-03-2014, 04:41 AM
Sigh.

I guess I knew that. I just didn't want to admit it to myself :-)

Geoff