Jump to content

[SOLVED] Alphabetical Sorting: Aa Bb, NOT ABab


Jfisher446

Recommended Posts

Looking all around the web for an answer on how to sort this out to no avail. I only hope there is a solution and someone can help me find it.

 

I have a string, for example: AbABCC

I want to sort it so all A's (upper or lower case) are together and all B's and so on. Like: AABbCC

 

Now this I understand that something like this is normally a homework assignment, but this is not. I am working on a genetics program and need the genotypes, whether they are a Wild (A) or mutant (a) to be together so that I can tell that Aa result is het for a mutation.

 

I've tried converting to ascii and back but it gives me the ABCDabcd result.

Any other thoughts?

That works. It actually works very well. The only complaint that I have is instead of AaBbCc, it's putting the lowercase first (aAbBcC.)

 

I would prefer it to be caps first, what I've done to get it how I want is put it together as a string, then strrev($string). Is there a more correct way of doing it?

I would assign a numerical value to each that would result in the correct sort order, A=1, a=2, B=3,... Then after the sort, change the values back to the actual character.

 

Or, you could swap each case (A becomes a, a becomes A, use natcasesort, then swap the case back.

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.