Jfisher446 Posted June 16, 2009 Share Posted June 16, 2009 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? Quote Link to comment Share on other sites More sharing options...
PFMaBiSmAd Posted June 16, 2009 Share Posted June 16, 2009 natcasesort will probably work. Quote Link to comment Share on other sites More sharing options...
Jfisher446 Posted June 16, 2009 Author Share Posted June 16, 2009 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? Quote Link to comment Share on other sites More sharing options...
PFMaBiSmAd Posted June 16, 2009 Share Posted June 16, 2009 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. Quote Link to comment Share on other sites More sharing options...
Jfisher446 Posted June 16, 2009 Author Share Posted June 16, 2009 Both sound like great ideas. I'll give them a try and kudos for the help! Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.