Link to home
Start Free TrialLog in
Avatar of Sathish David  Kumar N
Sathish David Kumar NFlag for India

asked on

how to sort value

Hi i have
value like

A10
B100
A2
AA1
AD200
32
11
A1

and the i want the result should be
A1
A2
A10
B2
B100
AD200
11
32

is that possible ??
Avatar of Guy Hengel [angelIII / a3]
Guy Hengel [angelIII / a3]
Flag of Luxembourg image

you want to sort by first the alpha/string part, and then by the numerical part.
so, you need to split the string accordingly, and apply the sorting based on the string and in case of equality of that by the numerical value behind
usually, the real issue behind is that the 2 parts should be really 2 parts, and not combined in the database behind, and only combined for the front-end if/as needed

I am not 100% sure about java code, just telling the general approach on how to do it and how to consider the "step back"
Where do these values exist (e.g. in an array or a list or a database table)?
Avatar of Sathish David  Kumar N

ASKER

actually its DB value  . so we can do it what ever we want ?
you can split (and orderby) in the database, wes
if you want specific code, you need to clarify which database you are using...
ASKER CERTIFIED SOLUTION
Avatar of Guy Hengel [angelIII / a3]
Guy Hengel [angelIII / a3]
Flag of Luxembourg image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
well, this gives the question on the actual requirements...
anyhow, I see AA1 in the input, but only A1 in the output...
I agree that the sample input and output do not match. 'AA1' is in the input but not the output and 'B2' is in the output but not the input. Regardless of what the input is or should be, the use of a length function sorts the alpha portion with the order of:
A, B, C, ..., Z, AA, AB, AC, ..., AZ, BA, BB, BC, ..., BZ, ... etc. until it reaches ZZ. (or a string of Zs for the maximum number of characters in the alpha portion of the value), making, for example, AD200 sort after B100 since AD would come after B.