<< Home | About Forth | About TurboForth | Download | Language Reference | Resources | Tutorials | YouTube >>
In Transient String Words in String Library
Performs a case-sensitive comparison of the topmost two strings on the string stack, returning true if their length and contents are identical, otherwise returning false. The strings are retained.
$" Hello" $" Hello" ==$? . \ displays -1 (same)
$" Hello" $" Hello" ==$? .
$" Hello" $" hello" ==$? . \ displays 0 (different)
$" Hello" $" hello" ==$? .
An error occurs if there are less than two strings on the string stack.
A case-insensitive comparison can be constructed as follows:
: same? ( -- flag ) ( ss: s1 s2 -- s1 s2 ) over$ over$ lcase$ swap$ lcase$ ==$? drop$ drop$ ;