StringTools[IsBalanced] - determine if fences in a string are balanced
|
Calling Sequence
|
|
IsBalanced( s, left, right )
|
|
Parameters
|
|
s
|
-
|
string; string to test
|
left
|
-
|
character; left fence character
|
right
|
-
|
character; right fence character
|
|
|
|
|
Description
|
|
•
|
The IsBalanced(s,left,right) command checks whether the string s is balanced with respect to fence characters left and right. The characters left and right must be distinct, but are otherwise unrestricted.
|
•
|
The string s is deemed balanced with respect to the given fence characters if each open fence in left is matched by a subsequent, corresponding close fence in right within s. Note that it is not sufficient that corresponding fences be equal in number in s.
|
•
|
If s is the empty string, or left and right are empty strings, the command returns true.
|
|
|
Examples
|
|
>
|
|
>
|
|
| (1) |
>
|
|
| (2) |
>
|
|
>
|
|
| (3) |
>
|
|
| (4) |
>
|
|
| (5) |
>
|
|
| (6) |
>
|
|
>
|
|
| (7) |
>
|
|
| (8) |
>
|
|
| (9) |
>
|
|
| (10) |
>
|
|
| (11) |
>
|
|
| (12) |
>
|
|
>
|
|
| (13) |
>
|
|
| (14) |
>
|
|
| (15) |
>
|
|
| (16) |
>
|
|
| (17) |
>
|
|
| (18) |
>
|
|
| (19) |
>
|
|
| (20) |
|
|
Download Help Document
Was this information helpful?