Sorting arrays by the first n characters

Do you have a question? Post it now! No Registration Necessary.  Now with pictures!

Threaded View

Hey guys,
Is there any way to sort an array without any regard to the characters
after an n number of characters? What I wanted to do was save a file
with the name being the date("U"); and then have a short string
appended to the end of that. So a possible file name would be like,
123978402-asdf.txt, and I would want to sort an array full of names
like that by just the first whatever characters, in this case, 9.

Re: Sorting arrays by the first n characters

Quoted text here. Click to load it

Why? If you don't care about the last characters, why would you bother if
also that part got sortet correctly instead of in some arbitary order?

Quoted text here. Click to load it

To compare two complete strings the correct way you would probably use
strcmp. To only compare up to 9 characters you could instead use strncmp,
but again, why?

In most cases when comparing a lot of strings strncmp will probably be
slower than strcmp. What would the gain be to maybe get a little
randomness in the result instead of a total predictable result?

regards Henrik
The address in the header is only to prevent spam. My real address is:
hc3(at) Examples of addresses which go to spammers:
root@localhost postmaster@localhost

Site Timeline