We are building a new experience for our SmartBear Community.
This site is now read-only. You can still browse and search as usual. Learn More
This site is now read-only. You can still browse and search as usual. Learn More
I am using the aqString.Compare and it's returning the incorrect result. The code looks like this:
var String1 = "15";
var String2 = "7"
var test = aqString.Compare(String1, String2, false)
test gets evaluated to -1, meaning String1 is less than String2. Clearly 15 is not less than 7, so I don't understand.
Has anyone else observed this? Is there something I'm doing wrong?
As baxatob pointed out,, aqString.Compare does a character comparison of strings. If you're looking at comparing numeric values to determine if one is less than or greater than another, I would suggest converting the strings to integers and then comparing.
var String1 = "15";
var String2 = "7";
if (aqConvert.StrToInt(String1) < aqConvert.StrToInt(String2)) {
Log.Message('Well, this didn't work');
}
else { Log.Message('Worked just fine')}Thanks tristaanogre, this worked for me.
As baxatob pointed out,, aqString.Compare does a character comparison of strings. If you're looking at comparing numeric values to determine if one is less than or greater than another, I would suggest converting the strings to integers and then comparing.
var String1 = "15";
var String2 = "7";
if (aqConvert.StrToInt(String1) < aqConvert.StrToInt(String2)) {
Log.Message('Well, this didn't work');
}
else { Log.Message('Worked just fine')}Thanks tristaanogre, this worked for me.
According to documentation aqString.Compare() method uses character codes (ASCII) and performing symbol-by-symbol and finishes once a difference is found.
In your case it finds the difference at first symbol, decides that 1 < 7 - and returns -1 as a result.
Try to change String1 = "85" and it returns 1.
If you need to compare the length of the strings, you can use aqString.GetLength() method.