March 2014 update
This commit is contained in:
parent
09687c4926
commit
a25938f123
1846 changed files with 21876 additions and 5203 deletions
3
Task/String-comparison/COBOL/string-comparison-1.cobol
Normal file
3
Task/String-comparison/COBOL/string-comparison-1.cobol
Normal file
|
|
@ -0,0 +1,3 @@
|
|||
"hello" = "hello" *> equality
|
||||
"helloo" <> "hello" *> inequality
|
||||
"aello" < "hello" *> lexical ordering
|
||||
3
Task/String-comparison/COBOL/string-comparison-2.cobol
Normal file
3
Task/String-comparison/COBOL/string-comparison-2.cobol
Normal file
|
|
@ -0,0 +1,3 @@
|
|||
FUNCTION STANDARD-COMPARE("hello", "hello") *> "="
|
||||
FUNCTION STANDARD-COMPARE("aello", "hello") *> "<"
|
||||
FUNCTION STANDARD-COMPARE("hello", "aello") *> ">"
|
||||
2
Task/String-comparison/COBOL/string-comparison-3.cobol
Normal file
2
Task/String-comparison/COBOL/string-comparison-3.cobol
Normal file
|
|
@ -0,0 +1,2 @@
|
|||
"hello " = "hello" *> True
|
||||
X"00" > X"0000" *> True
|
||||
14
Task/String-comparison/Icon/string-comparison.icon
Normal file
14
Task/String-comparison/Icon/string-comparison.icon
Normal file
|
|
@ -0,0 +1,14 @@
|
|||
procedure main(A)
|
||||
s1 := A[1] | "a"
|
||||
s2 := A[2] | "b"
|
||||
# These first four are case-sensitive
|
||||
s1 == s2 # Are they equal?
|
||||
s1 ~== s2 # Are they unequal?
|
||||
s1 << s2 # Does s1 come before s2?
|
||||
s1 >> s2 # Does s1 come after s2?
|
||||
map(s1) == map(s2) # Caseless comparison
|
||||
"123" >> "12" # Lexical comparison
|
||||
"123" > "12" # Numeric comparison
|
||||
"123" >> 12 # Lexical comparison (12 coerced into "12")
|
||||
"123" > 12 # Numeric comparison ("123" coerced into 123)
|
||||
end
|
||||
25
Task/String-comparison/Perl/string-comparison.pl
Normal file
25
Task/String-comparison/Perl/string-comparison.pl
Normal file
|
|
@ -0,0 +1,25 @@
|
|||
use v5.16; # ...for fc(), which does proper Unicode casefolding.
|
||||
# With older Perl versions you can use lc() as a poor-man's substitute.
|
||||
|
||||
sub compare {
|
||||
my ($a, $b) = @_;
|
||||
my $A = "'$a'";
|
||||
my $B = "'$b'";
|
||||
|
||||
print "$A and $B are lexically equal.\n" if $a eq $b;
|
||||
print "$A and $B are not lexically equal.\n" if $a ne $b;
|
||||
|
||||
print "$A is lexically before $B.\n" if $a lt $b;
|
||||
print "$A is lexically after $B.\n" if $a gt $b;
|
||||
|
||||
print "$A is not lexically before $B.\n" if $a ge $b;
|
||||
print "$A is not lexically after $B.\n" if $a le $b;
|
||||
|
||||
print "The lexical relationship is: ", $a cmp $b, "\n";
|
||||
print "The case-insensitive lexical relationship is: ", fc($a) cmp fc($b), "\n";
|
||||
print "\n";
|
||||
}
|
||||
|
||||
compare('Hello', 'Hello');
|
||||
compare('5', '5.0');
|
||||
compare('perl', 'Perl');
|
||||
14
Task/String-comparison/Scheme/string-comparison.ss
Normal file
14
Task/String-comparison/Scheme/string-comparison.ss
Normal file
|
|
@ -0,0 +1,14 @@
|
|||
;; Comparing two strings for exact equality
|
||||
(string=? "hello" "hello")
|
||||
|
||||
;; Comparing two strings for inequality
|
||||
(not (string=? "hello" "Hello"))
|
||||
|
||||
;; Checking if the first string is lexically ordered before the second
|
||||
(string<? "bar" "foo")
|
||||
|
||||
;; Checking if the first string is lexically ordered after the second
|
||||
(string>? "foo" "bar")
|
||||
|
||||
;; case insensitive comparison
|
||||
(string-ci=? "hello" "Hello")
|
||||
Loading…
Add table
Add a link
Reference in a new issue