Login Page - Create Account

Support Board


Date/Time: Wed, 22 Jan 2025 00:23:56 +0000



Post From: String Compare function

[2018-08-21 12:55:53]
Richard Chinn - Posts: 28
Hi Guys,

I am having trouble with the string compare function.
The documentation is unclear to me and it lists the same function twice but not the same way as in the example so I am not sure if I am doing something wrong.

How To Compare Strings
You can compare a SCString to another string using the SCString CompareNoCase(const char* String, int NumChars) or SCString CompareNoCase(SCString String, int NumChars) functions.
These functions compare String to the string in the SCString these functions are called from, using a case-insensitive comparison up to the first NumChars characters of the two strings.
If NumChars is left out, then the function compares all the characters of the two strings.
The function returns 0 if both strings are equal up to the given length, an integer < 0 if String is lexically less than the string in SCString, and an integer > 0 if String is lexically greater than the string in SCString.

Code Example
int Result;
Result = sc.Symbol.CompareNoCase("ABC");

SCString SymbolToCompare("ABC");
Result = sc.Symbol.CompareNoCase(SymbolToCompare);


It works like I think it should if I do these:
SCString abc = "ABC";
SCString def = "DEF";
int result = sc.Symbol.CompareNoCase(abc) == sc.Symbol.CompareNoCase(def); // returns 0

SCString abc = "ABC";
SCString def = "ABC";
int result = sc.Symbol.CompareNoCase(abc) == sc.Symbol.CompareNoCase(def); // returns 1

It doesn't work like I think it should if I do these:

SCString abc = "ABC";
SCString def = "AB1";
int result = sc.Symbol.CompareNoCase(abc) == sc.Symbol.CompareNoCase(def); // returns 1

SCString abc = "ABC";
SCString def = "A1C";
int result = sc.Symbol.CompareNoCase(abc) == sc.Symbol.CompareNoCase(def); // returns 1

I also tried these using the NumChars parameter with the same result.

Thanks,
Richard