Difference between revisions of "Compare.strings"

From AGI Wiki
Jump to navigationJump to search
(Created page with "The '''compare.strings''' test command compares two strings. It returns TRUE if the strings are the same. == Syntax == compare.strings(str sA, string|...")
 
 
Line 33: Line 33:
 
set.string(s1, "Some Text");
 
set.string(s1, "Some Text");
 
set.string(s2, "  some:TEXT!");
 
set.string(s2, "  some:TEXT!");
if(compare.strings(s1, s2)) {  
+
if(compare.strings(s1, s2))
 +
  {  
 
   print("SURPRISE! these two strings are the same!");
 
   print("SURPRISE! these two strings are the same!");
}
+
  }
 
</syntaxhighlight>
 
</syntaxhighlight>
  

Latest revision as of 11:51, 14 April 2019

The compare.strings test command compares two strings. It returns TRUE if the strings are the same.

Syntax

compare.strings(str sA, str sB)

Remarks

Test commands are only valid in an if statement.

This statement can be combined with the NOT operator to create a 'strings not equal' test.

The comparison is not case-sensitive, and the following characters are ignored:

  • space
  • tab
  • period
  • comma
  • semicolon
  • colon
  • single-quote
  • exclamation point
  • dash

If you are not aware of this, you may struggle in trying to understand why your code is not working as expected.

Possible Errors

AGI does not check that a valid string argument is passed. If an invalid string number is used (the limit is 24 [s0 - s23], except for versions 2.089, 2.272 and 3.002.149, which have a limit of 12 [s0 - s11]) AGI will read data from memory used for other purposes, and the returned value will be meaningless.

Example

Code:
set.string(s1, "Some Text");
set.string(s2, "   some:TEXT!");
if(compare.strings(s1, s2))
  { 
  print("SURPRISE! these two strings are the same!");
  }

Technical Information

Required Interpreter Version: Available in all AGI versions.
Byte-Code Value: 15 (0x0F hex)

See Also

Test Commands
String Commands