Data commit
This commit is contained in:
parent
7387c8f97b
commit
cb5bb5e222
199093 changed files with 3378972 additions and 0 deletions
40
Task/String-comparison/XPL0/string-comparison.xpl0
Normal file
40
Task/String-comparison/XPL0/string-comparison.xpl0
Normal file
|
|
@ -0,0 +1,40 @@
|
|||
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);
|
||||
]
|
||||
Loading…
Add table
Add a link
Reference in a new issue