String comparison: Difference between revisions
Content added Content deleted
(Added uBasic/4tH version) |
(Added XPL0 example.) |
||
Line 4,246: | Line 4,246: | ||
1100 <= 200 -> true |
1100 <= 200 -> true |
||
1100 >= 200 -> false |
1100 >= 200 -> false |
||
</pre> |
|||
=={{header|XPL0}}== |
|||
{{trans|Wren}} |
|||
<lang XPL0>include xpllib; \provides StrLen, ToLower, StrCopy, and StrCmp |
|||
proc StrToLower(A, B); |
|||
char A, B, I; |
|||
for I:= 0 to StrLen(B) do A(I):= ToLower(B(I)); |
|||
proc CompareStrings(A, B, Sens); |
|||
char A, B, Sens, C, D; |
|||
[C:= Reserve(StrLen(A)+1); |
|||
D:= Reserve(StrLen(B)+1); |
|||
Text(0, "Comparing "); Text(0, A); Text(0, " and "); Text(0, B); Text(0, ", "); |
|||
if Sens then |
|||
[Text(0, "case sensitively:^m^j"); |
|||
StrCopy(C, A); |
|||
StrCopy(D, B); |
|||
] |
|||
else [Text(0, "case insensitively:^m^j"); |
|||
StrToLower(C, A); |
|||
StrToLower(D, B); |
|||
]; |
|||
Text(0, " "); Text(0, A); Text(0, " < "); Text(0, B); Text(0, " -> "); |
|||
Text(0, if StrCmp(C, D) < 0 then "true" else "false"); CrLf(0); |
|||
Text(0, " "); Text(0, A); Text(0, " > "); Text(0, B); Text(0, " -> "); |
|||
Text(0, if StrCmp(C, D) > 0 then "true" else "false"); CrLf(0); |
|||
Text(0, " "); Text(0, A); Text(0, " = "); Text(0, B); Text(0, " -> "); |
|||
Text(0, if StrCmp(C, D) = 0 then "true" else "false"); CrLf(0); |
|||
Text(0, " "); Text(0, A); Text(0, " # "); Text(0, B); Text(0, " -> "); |
|||
Text(0, if StrCmp(C, D) # 0 then "true" else "false"); CrLf(0); |
|||
Text(0, " "); Text(0, A); Text(0, " <= "); Text(0, B); Text(0, " -> "); |
|||
Text(0, if StrCmp(C, D) <= 0 then "true" else "false"); CrLf(0); |
|||
Text(0, " "); Text(0, A); Text(0, " >= "); Text(0, B); Text(0, " -> "); |
|||
Text(0, if StrCmp(C, D) >= 0 then "true" else "false"); CrLf(0); |
|||
CrLf(0); |
|||
]; |
|||
[CompareStrings("cat", "dog", true); |
|||
CompareStrings("Rat", "RAT", true); |
|||
CompareStrings("Rat", "RAT", false); |
|||
CompareStrings("1100", "200", true); |
|||
]</lang> |
|||
{{out}} |
|||
<pre> |
|||
Comparing cat and dog, case sensitively: |
|||
cat < dog -> true |
|||
cat > dog -> false |
|||
cat = dog -> false |
|||
cat # dog -> true |
|||
cat <= dog -> true |
|||
cat >= dog -> false |
|||
Comparing Rat and RAT, case sensitively: |
|||
Rat < RAT -> false |
|||
Rat > RAT -> true |
|||
Rat = RAT -> false |
|||
Rat # RAT -> true |
|||
Rat <= RAT -> false |
|||
Rat >= RAT -> true |
|||
Comparing Rat and RAT, case insensitively: |
|||
Rat < RAT -> false |
|||
Rat > RAT -> false |
|||
Rat = RAT -> true |
|||
Rat # RAT -> false |
|||
Rat <= RAT -> true |
|||
Rat >= RAT -> true |
|||
Comparing 1100 and 200, case sensitively: |
|||
1100 < 200 -> true |
|||
1100 > 200 -> false |
|||
1100 = 200 -> false |
|||
1100 # 200 -> true |
|||
1100 <= 200 -> true |
|||
1100 >= 200 -> false |
|||
</pre> |
</pre> |
||