string equal

Tests whether two strings are the same text.

string equal ?-nocase? ?-length N? A B

Description

Gives 1 when A and B have the same characters in the same order, else 0. The test is on the text: 1 and 1.0 are different strings, while expr {1 == 1.0} is true. Two empty strings are equal.

The options follow the rules of string compare.

Arguments

ArgumentTypeDefaultDescription
AstringrequiredThe first string.
BstringrequiredThe second string.

Options

OptionTypeDefaultSummary
-nocaseflagnoneTreats each uppercase letter as its lowercase letter.
-lengthintegernoneTests only the first N characters of each string.

-nocase

Treats each uppercase letter as its lowercase letter.

Compares the strings after a change of each letter to lowercase, also for letters outside ASCII, such as É and é.

% string equal -nocase ABC abc
1

% string equal -nocase "É" "é"
1
% string equal -nocase a b c
bad option "a": must be -nocase or -length
-errorcode TCL LOOKUP INDEX option

-length N

Tests only the first N characters of each string.

Tests at most the first N characters of A and of B. N of 0 gives 1, and a negative N tests the whole strings.

% string equal -length 2 abc abd
1

% string equal -length 0 a b
1

% string equal -length -1 abc abd
0
% string equal -length x a b
expected integer but got "x"
-errorcode NONE

Returns

1 or 0.

Examples

% string equal abc abc
1

% string equal 1 1.0
0

% string equal "" ""
1

Errors

% string equal a
wrong # args: should be "string equal ?-nocase? ?-length int? string1 string2"
-errorcode TCL WRONGARGS

Facts

Capability
None.
Tcl release
Tcl 9.1 and 8.6.
Since
ztcl 1.0.0-beta.1

See also