spacer graphic
spacer graphic
Montage of games AGS Logo
spacer graphic

 

spacer graphic
Menu
spacer graphic Home
About
News
Features
Download AGS
spacer graphic Games 
Games main page
Award Winners
Picks of the month
Short games
Medium length games
Full length games
In Production
Hints & Tips
Community
Forums
AGSers World Map
Member websites
Chat
Resources
Tutorials
FAQ
Knowledge Base
Downloads
Links
AGS-related links
* AGS Manual
  * Scripting
    * String functions

CompareTo

(Formerly known as global function StrCaseComp, which is now obsolete)
(Formerly known as global function StrComp, which is now obsolete)

String.CompareTo(string str2, optional bool caseSensitive)
Compares the specified string to STR2. caseSensitive determines whether "Dog" and "dog" are equivalent; case sensitivity is off by default.

Returns 0 if the strings match, a number less than 0 if this string is earlier in the alphabet than STR2, and a number greater than 0 if this string is later in the alphabet than STR2.

TIP: To do a case-sensitive comparison of two strings, it's easier to just use the == operator.

Example:

String mytext = "Hello";
if (mytext.CompareTo("hello") == 0) {
  Display("Strings match with case sensitivity off!");
}
else {
  Display("Strings don't match with case sensitivity off!");
}

if (mytext == "hello") { Display("Strings match with case sensitivity on!"); } else { Display("Strings don't match with case sensitivity on!"); }

will display "Strings match with case sensitivity off!", and then "Strings don't match with case sensitivity on!".

User comments and notes
There are currently no user comments on this page.
The user comment facility is currently disabled.