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?

Link to comment
Share on other sites

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?

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.