strCmp Function - X++ Code

Rumman Ansari   Software Engineer   2023-10-25   536 Share
☰ Table of Contents

Table of Content:


Compares two text strings.

Syntax:


int strCmp(str text1, str text2)

Parameters

Parameter

Description

text1

The first string.

text2

The second string.


Return Value

0 if the two strings are identical, 1 if the first string sorts earlier, or -1 if the second string sorts earlier.

Remarks

The comparison performed by this method is case-sensitive.

  • print strCmp("abc", "abc"); //Returns the value 0.

  • print strCmp("abc", "ABC"); //Returns the value 1.

  • print strCmp("aaa", "bbb"); //Returns the value -1.

  • print strCmp("ccc", "bbb"); //Returns the value 1.



internal final class CodePractice
{
   public static void main(Args _args)
   {
       setPrefix("Output");
       int result = strCmp("apple", "apple"); //Returns the value 0.
       Info(strFmt("%1", result));
 
       int result1 = strCmp("apple", "banana"); //Returns the value -1.
       Info(strFmt("%1", result1));
 
       int result2 = strCmp("banana", "apple"); //Returns the value 1.
       Info(strFmt("%1", result2));
 
       int result3 = strCmp("abc", "abc"); //Returns the value 0.
       Info(strFmt("%1", result3));
 
       int result4 = strCmp("abc", "ABC"); //Returns the value 1.
       Info(strFmt("%1", result4));
 
       int result5 = strCmp("aaa", "bbb"); //Returns the value -1.
       Info(strFmt("%1", result5));
 
       int result6 = strCmp("ccc", "bbb"); //Returns the value 1.
       Info(strFmt("%1", result6));
 
       int result7 = strCmp("Human", "Humbn"); //Returns the value -1.
       Info(strFmt("%1", result7));
 
       int result8 = strCmp("Humbn", "Human"); //Returns the value 1.
       Info(strFmt("%1", result8));
   
   }
 
}

Output:


0
-1
1
0
1
-1
1
-1
1