Solved

sort the alpha numeric value

Posted on 2002-05-04
4
1,931 Views
Last Modified: 2008-02-01
Hi all,

   I am using foxpro db!

   I have a string field in a table. But the value in this field will be in the alphanumeric format.
For e.g., String123, String23, Strinf150, String30, and String1111. Now if I fetched the data by sorting
on this field, the data is written as, String1111, String123, Strinf150, String23, and String30. but
I need the output in the following order,
String23, String30, String123, Strinf150, and String1111

i.e., if the data is compared in the alphanumeric format I could got the expected result but it is comparing
as a string. Is there any command to specify to sort the values based on alpha numeric instead of just
a string?

    I had posted the same question in the Foxpro topic, I got some comments "
"select * from test order by val(substring(chkColumn,7))"

  but if I execute this statement, it gives "Column " is not found" error message.

  but a statement like this with appropriat function works in the MS-SQL enviroment.

  I will be very thankful for your answers!

siva
0
Comment
Question by:ksivananth
  • 2
4 Comments
 
LVL 18

Expert Comment

by:bobbit31
ID: 6989777
have you tried:

select substring(chkColumn, 7) as orderCol, * from test order by orderCol
0
 
LVL 18

Expert Comment

by:bobbit31
ID: 6989799
or

select substring(chkColumn, 7) as orderCol, * from test order by val(orderCol)
0
 

Accepted Solution

by:
dmkoelle earned 100 total points
ID: 6992048
I have written a Java comparator that does exactly what you're looking for.  See http://www.davekoelle.com/usability/alphanum.html

If you're looking for a "select" statement instead of Java code, I recommend asking your question in a different forum.

Hope this helps!
Dave
0
 
LVL 26

Author Comment

by:ksivananth
ID: 7005909
Hi dmkoelle,

   Really the comparator class was very usefull for me. I thought it will be very slow in performance so I avoided intially. Then I did put a try, I couldn't find that much differences in performance.

   In your code, to check the digit you need not use that algorithm because it is already available in the Java's Character class. Anyway thanks a lot!

with cheers
siva
0

Featured Post

What Should I Do With This Threat Intelligence?

Are you wondering if you actually need threat intelligence? The answer is yes. We explain the basics for creating useful threat intelligence.

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
ArrayLists in ArrayLists/HashMaps? 4 41
mapShare challenge 13 70
word0 challenge 4 54
what is a "java.lang.System Property"   ? 20 41
INTRODUCTION Working with files is a moderately common task in Java.  For most projects hard coding the file names, using parameters in configuration files, or using command-line arguments is sufficient.   However, when your application has vi…
In this post we will learn how to connect and configure Android Device (Smartphone etc.) with Android Studio. After that we will run a simple Hello World Program.
Viewers will learn about arithmetic and Boolean expressions in Java and the logical operators used to create Boolean expressions. We will cover the symbols used for arithmetic expressions and define each logical operator and how to use them in Boole…
Viewers will learn about if statements in Java and their use The if statement: The condition required to create an if statement: Variations of if statements: An example using if statements:

743 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

15 Experts available now in Live!

Get 1:1 Help Now