1. Dean Helsley
  2. PowerBuilder
  3. Tuesday, 17 August 2021 17:59 PM UTC

I'm confused by the results of a string comparison.  I only discovered this because it's causing an issue with some legacy code we are migrating for a client from the mainframe.

I thought any non-blank value would be greater than a space, but the minus sign is not.  In the debugger, I added the following watch expressions:

 "a" > " "  (this is true)

 "-" > " "  (this is false)

Is this a bug or expected behavior?  It's causing an issue when running the client's converted code because a loop is exiting when it shouldn't based on that comparison.  I don't know why someone would have a single dash as a key value, but that's what's in the data.  That might be an EBCDIC to ASCII conversion issue which we're also investigating.  Regardless, I would expect a char(45) to be greater than a char(32).

 

John Fauss Accepted Answer Pending Moderation
  1. Tuesday, 17 August 2021 19:13 PM UTC
  2. PowerBuilder
  3. # 1

This is not a definitive answer, Dean, but if one of the values being compared is ASCII-encoded ANSI, then this behavior could be due to comparison of Unicode with ANSI. Since v10, PB strings by default are represented using Unicode16LE (16-bit, Little Endian) encoding. If the information being processed is from a file that contains ANSI (ASCII127) and the information is not translated to Unicode, there could very well be comparison issues.

Comment
There are no comments made yet.
Miguel Leeuwe Accepted Answer Pending Moderation
  1. Wednesday, 18 August 2021 03:56 AM UTC
  2. PowerBuilder
  3. # 2

In addition to what John has said, if you convert the char values it will work (cannot be strings):

 

integer li_1, li_2
li_1 = asc('-')
li_2 = asc(' ')
if li_1 > li_2 then
....
end if
Comment
There are no comments made yet.
Dean Helsley Accepted Answer Pending Moderation
  1. Wednesday, 18 August 2021 15:08 PM UTC
  2. PowerBuilder
  3. # 3

I understand about the encoding, and that did cross my mind, however in a simple PB debugger watch expression, apparently '-' is not greater than a space.  That just seems wrong to me.

Comment
  1. Miguel Leeuwe
  2. Wednesday, 18 August 2021 16:09 PM UTC
Yes I agree. I guess it has something to do on what's preferred when sorting data on a string column / value. (first all the 'funny' characters, then the rest).
  1. Helpful
There are no comments made yet.
  • Page :
  • 1


There are no replies made for this question yet.
However, you are not allowed to reply to this question.