473,378 Members | 1,507 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,378 software developers and data experts.

evaluating strings

I need to evaluate two strings for their order.

The strings contain Letters (A thru Z upper case only) and Numbers
(0-9) and the decimal point (.).

I need an order like the list that follows: ( it's just an example
of the order )

0
1
2
3
A.0
A.1
A.2
B
C
Z
AA.1
AA.4
AA
AB
AZ

Currently I am testing two strings:

if(string1 < string 2)

It seemed to work ok until I encountered (AB < Z ) as TRUE, it
evaluated backwards having Z greater than AB. I found true that :

(AB A)

but

(AB < B)
(AB < C)

are the single characters in the strings being evaluated as "A "
with a space after the letter? That's the only thing that's
logical. If so, how do I make it evaluate correctly.

Thanks in advance.

JC

Aug 24 '06 #1
7 2237
temp34k45k wrote:
I need to evaluate two strings for their order.

The strings contain Letters (A thru Z upper case only) and Numbers
(0-9) and the decimal point (.).

I need an order like the list that follows: ( it's just an example
of the order )

0
1
2
3
A.0
A.1
A.2
B
C
Z
AA.1
AA.4
AA
AB
AZ

Currently I am testing two strings:

if(string1 < string 2)

It seemed to work ok until I encountered (AB < Z ) as TRUE, it
evaluated backwards having Z greater than AB. I found true that :

(AB A)

but

(AB < B)
(AB < C)

are the single characters in the strings being evaluated as "A "
with a space after the letter? That's the only thing that's
logical. If so, how do I make it evaluate correctly.
a) post code that shows the problem. Without code, we can only guess.

b) Here is my guess: Did you use char* to represent the strings in your
program? Use std::string instead. If you use operator< on char* it will not
give you the lexicographic ordering but undefined results.
Best

Kai-Uwe Bux

Aug 24 '06 #2
temp34k45k wrote:
I need to evaluate two strings for their order.

The strings contain Letters (A thru Z upper case only) and Numbers
(0-9) and the decimal point (.).

I need an order like the list that follows: ( it's just an example
of the order )

0
1
2
3
A.0
A.1
A.2
B
C
Z
AA.1
AA.4
AA
AB
AZ

Currently I am testing two strings:

if(string1 < string 2)

It seemed to work ok until I encountered (AB < Z ) as TRUE, it
evaluated backwards having Z greater than AB. I found true that :

(AB A)

but

(AB < B)
(AB < C)

are the single characters in the strings being evaluated as "A "
with a space after the letter? That's the only thing that's
logical. If so, how do I make it evaluate correctly.

Thanks in advance.

JC
Strings are compared lexicographically (see
http://www.sgi.com/tech/stl/lexicogr..._compare.html). If that is
not what you want, implement your own comparison function.

Cheers! --M

Aug 24 '06 #3
"temp34k45k" <ja***********@na.biomerieux.comwrites:
I need to evaluate two strings for their order.

The strings contain Letters (A thru Z upper case only) and Numbers
(0-9) and the decimal point (.).

I need an order like the list that follows: ( it's just an example
of the order )

0
1
2
3
A.0
A.1
A.2
B
C
Z
AA.1
AA.4
AA
AB
AZ

Currently I am testing two strings:

if(string1 < string 2)

It seemed to work ok until I encountered (AB < Z ) as TRUE, it
evaluated backwards having Z greater than AB. I found true that :

(AB A)

but

(AB < B)
(AB < C)
( ((int) "A" + (int) "B") < (int) "B" )
Aug 24 '06 #4
Gary Wessle <ph****@yahoo.comwrites:
"temp34k45k" <ja***********@na.biomerieux.comwrites:
>I need to evaluate two strings for their order.

The strings contain Letters (A thru Z upper case only) and Numbers
(0-9) and the decimal point (.).

I need an order like the list that follows: ( it's just an example
of the order )

0
1
2
3
A.0
A.1
A.2
B
C
Z
AA.1
AA.4
AA
AB
AZ

Currently I am testing two strings:

if(string1 < string 2)

It seemed to work ok until I encountered (AB < Z ) as TRUE, it
evaluated backwards having Z greater than AB. I found true that :

(AB A)

but

(AB < B)
(AB < C)

( ((int) "A" + (int) "B") < (int) "B" )
also try this

wchar_t x = 'AB';
wchar_t y = 'AC';
cout << ((int) x < (int) y) << endl;
Aug 24 '06 #5
Gary Wessle wrote:
"temp34k45k" <ja***********@na.biomerieux.comwrites:
>I need to evaluate two strings for their order.

The strings contain Letters (A thru Z upper case only) and Numbers
(0-9) and the decimal point (.).

I need an order like the list that follows: ( it's just an example
of the order )

0
1
2
3
A.0
A.1
A.2
B
C
Z
AA.1
AA.4
AA
AB
AZ

Currently I am testing two strings:

if(string1 < string 2)

It seemed to work ok until I encountered (AB < Z ) as TRUE, it
evaluated backwards having Z greater than AB. I found true that :

(AB A)

but

(AB < B)
(AB < C)

( ((int) "A" + (int) "B") < (int) "B" )
Do you realize that this code does the following:

a) convert a pointer to some preallocated string literal "A" to an int.
(this int know contains an implementation defined value that maybe
related to the address of the char A in the string literal.)
b) add to this an int obtained in the same way from the address of the B
in the second string literal.
c) compare this to an int obtained from the address of the B in some other
string literal (and in fact, the compiler is free to use a third
literal but also free to reuse the second).

The result is devoid of any meaning.
Best

Kai-Uwe Bux
Aug 24 '06 #6

"temp34k45k" <ja***********@na.biomerieux.comwrote in message
news:11**********************@m73g2000cwd.googlegr oups.com...
>I need to evaluate two strings for their order.

The strings contain Letters (A thru Z upper case only) and Numbers
(0-9) and the decimal point (.).

I need an order like the list that follows: ( it's just an example
of the order )

0
1
2
3
A.0
A.1
A.2
B
C
Z
AA.1
AA.4
AA
AB
AZ

Currently I am testing two strings:

if(string1 < string 2)

It seemed to work ok until I encountered (AB < Z ) as TRUE, it
evaluated backwards having Z greater than AB. I found true that :

(AB A)
Right. The first characters are identical ('A'), but the string "AB" has
more characters after that, and "A" does not, so "A" must come first. Like
"admit" and "admittance" in the dictionary, where "admit" comes first.
>
but

(AB < B)
(AB < C)
Right, because in the first case 'A' is less than 'B', and in the second
case because 'A' is less than 'C'. No need to look further.
are the single characters in the strings being evaluated as "A "
with a space after the letter? That's the only thing that's
logical.
No, that's not what happens. Looking at the strings "Z" and "AB", the first
character is compared first. The value for the char 'A' is less than for
'Z', so we know already that the string "AB" must come first. No need to
compare further. In the dictionary, the word "aardvark" comes before the
word "up", right? Just like that, "AB" comes before "Z".

The length of the string is only an issue when comparing two string which
are otherwise identical up to the point where one of them ends. The shorter
one comse first. But ONLY if they're identical up to the end of the shorter
one. That's why "AA" comes before "AAAA". They're identical up to the
second 'A', but then "AA" ends, while "AAAA" has two more characters to go,
so it comes later in the order (normally).
If so, how do I make it evaluate correctly.
It is doing it "correctly". If you want it to do things another way, then
you have to write a comparison function yourself, with its own set of rules.

But those rules look like pretty odd to me. You're putting "AA.1" before
"AA", whereas (I'm assuming) "AAB" would come AFTER "AA". This makes the
'.' character special, and makes your job of parsing more difficult, because
you need to handle different characters with different code, and not just
compare character-by-character until there's a difference or until one or
both strings ends, as is usually done.

-Howard
Aug 25 '06 #7
Howard wrote:
"temp34k45k" <ja***********@na.biomerieux.comwrote in message
news:11**********************@m73g2000cwd.googlegr oups.com...
I need to evaluate two strings for their order.

The strings contain Letters (A thru Z upper case only) and Numbers
(0-9) and the decimal point (.).

I need an order like the list that follows: ( it's just an example
of the order )

0
1
2
3
A.0
A.1
A.2
B
C
Z
AA.1
AA.4
AA
AB
AZ

Currently I am testing two strings:

if(string1 < string 2)

It seemed to work ok until I encountered (AB < Z ) as TRUE, it
evaluated backwards having Z greater than AB. I found true that :

(AB A)

Right. The first characters are identical ('A'), but the string "AB" has
more characters after that, and "A" does not, so "A" must come first. Like
"admit" and "admittance" in the dictionary, where "admit" comes first.

but

(AB < B)
(AB < C)

Right, because in the first case 'A' is less than 'B', and in the second
case because 'A' is less than 'C'. No need to look further.
are the single characters in the strings being evaluated as "A "
with a space after the letter? That's the only thing that's
logical.

No, that's not what happens. Looking at the strings "Z" and "AB", the first
character is compared first. The value for the char 'A' is less than for
'Z', so we know already that the string "AB" must come first. No need to
compare further. In the dictionary, the word "aardvark" comes before the
word "up", right? Just like that, "AB" comes before "Z".

The length of the string is only an issue when comparing two string which
are otherwise identical up to the point where one of them ends. The shorter
one comse first. But ONLY if they're identical up to the end of the shorter
one. That's why "AA" comes before "AAAA". They're identical up to the
second 'A', but then "AA" ends, while "AAAA" has two more characters to go,
so it comes later in the order (normally).
If so, how do I make it evaluate correctly.

It is doing it "correctly". If you want it to do things another way, then
you have to write a comparison function yourself, with its own set of rules.

But those rules look like pretty odd to me. You're putting "AA.1" before
"AA", whereas (I'm assuming) "AAB" would come AFTER "AA". This makes the
'.' character special, and makes your job of parsing more difficult, because
you need to handle different characters with different code, and not just
compare character-by-character until there's a difference or until one or
both strings ends, as is usually done.

-Howard
I wrote my own rules and it works very simple. Shorter strings come
first because the only time a . is encountered is when both strings to
compare have a . in them. So if I encounter single char with mulitple
char string the single will be less than the multiple. I didn't know
that it was only using the first A of the AB when comparing to Z. I
thought is was using the ascii value of B appended to A (065066) to
compare to Z (090) not 65 < 90. Thanks for the input on string
comparisons.

Grant

Aug 28 '06 #8

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

6
by: Michael L. Labbe | last post by:
Hello. I'm an experienced programmer who is evaluating learning Python if it is applicable to a few projects. The programs I am going to list are production software - they are not throwaway toy...
25
by: Jason | last post by:
Hi, below is example code which demonstrates a problem I have encountered. When passing a number to a function I compare it with a string's size and then take certain actions, unfortunately during...
10
by: Jason Heyes | last post by:
Are the side effects of evaluating expr1 resolved before expr2 is evaluated? if (expr1 && expr2) Thanks.
2
by: Sanjeev | last post by:
Hi, I am evaluating Lumigent's Entegra for doing security and business audit of some of the critical database(s) in the company I work for. I would like to know what has been your experience in...
0
by: Boulent Mustafa | last post by:
Using Microsoft Access 2000, I am defining a bunch of fields all with default values. The reason for this is that I have 5 text fields, each of which can have 5 permutations depending on the...
10
by: John A Grandy | last post by:
What's the proper way to write a validation regex so that all leading and trailing spaces are trimmed before evaluation ? Thanks.
4
by: louise raisbeck | last post by:
Hi there, I have created a vb server function which i want to evaluate when a server control button is clicked (only!) however it is evaluating the code on load even though i havent put it into the...
3
by: Ashok | last post by:
Dear Plese help me. if there is x=5 y=10 now i want z=15 z="x+y" How it is possible?
6
by: bugnthecode | last post by:
I'm writing a program to send data over the serial port. I'm using pyserial, and I'm on WindowsXP. When I use literals I can get the data accross how I want it for example: 1 2 3 4...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.