StringEqual
bool StringEqual(string a, string b, bool caseSensitive);
Compare two strings depending of the case sensitivness.
Parameters
- string a
First string to compare
- string b
Second string to compare
- bool caseSensitive
- true: the case is important. Eg "A" is not equal to "a". This is the same as using "a" == "A".
- false: the case does not matter. Eg "A" is equal to "a"
Return value
bool -
- true: the two strings are equal
- false: the two strings are not equal
Examples
- Example #1: Sample Usage
bool b; b = StringEqual("abc", "ABC", true); b = ("abc" == "ABC"); // b = false; Because it is case sensitive b = StringEqual("abc", "ABC", false); // b = true; Because it is not case sensitive b = StringEqual("abc ", "abc", false); // b = false; Because there is no trimming applied b = StringEqual("é", "É", false); // Syntax error. Galaxy does not support UTF8 ...
- Example #2: Command Handling
// We want to implement a basic command handling for our map. // Usage: // - kill <player> // - restart bool TriggerHandleCommand (bool checkConds, bool doActions) { // First we get the message and the first word into variables string msg = EventChatMessage(false); string cmd = StringWord(msg, 1); // Then we compare the command to the available ones if (StringEqual(cmd, "-kill", false)) { // The first word is -kill (or -KILL ...) // so we call the appropriate function with the second word ExecuteKill(StringWord(msg, 2)); } else if (StringEqual(cmd, "-restart", false)) { ExecuteRestart(); } return true; } // Bind a trigger that will be executed anytime the player 1 types "-" trigger t = TriggerCreate("TriggerHandleCommand"); TriggerAddEventChatMessage(t, 1, "-", false); // When a player types "-kill vjeux" // It calls the function ExecuteKill("vjeux")