Sync
This commit is contained in:
parent
6f050a029e
commit
776bba907c
3887 changed files with 59894 additions and 7280 deletions
|
|
@ -0,0 +1,31 @@
|
|||
MODULE StringComparision;
|
||||
IMPORT StdLog,Strings;
|
||||
|
||||
PROCEDURE Do*;
|
||||
VAR
|
||||
str1,str2,aux1,aux2: ARRAY 128 OF CHAR;
|
||||
BEGIN
|
||||
str1 := "abcde";str2 := "abcde";
|
||||
StdLog.String(str1+" equals " + str2 + ":> ");StdLog.Bool(str1 = str2);StdLog.Ln;
|
||||
str2 := "abcd";
|
||||
StdLog.String(str1+" equals " + str2 + ":> ");StdLog.Bool(str1 = str2);StdLog.Ln;
|
||||
StdLog.String(str1+" greater than " + str2 + ":> ");StdLog.Bool(str1 > str2);StdLog.Ln;
|
||||
StdLog.String(str1+" lower than " + str2 + ":> ");StdLog.Bool(str1 < str2);StdLog.Ln;
|
||||
|
||||
str2 := "ABCDE";
|
||||
StdLog.String(str1+" equals " + str2 + ":> ");StdLog.Bool(str1 = str2);StdLog.Ln;
|
||||
StdLog.String(str1+" greater than " + str2 + ":> ");StdLog.Bool(str1 > str2);StdLog.Ln;
|
||||
StdLog.String(str1+" lower than " + str2 + ":> ");StdLog.Bool(str1 < str2);StdLog.Ln;
|
||||
|
||||
Strings.ToLower(str1,aux1);Strings.ToLower(str2,aux2);
|
||||
StdLog.String(str1+" equals (case insensitive) " + str2 + ":> ");StdLog.Bool(aux1 = aux2);StdLog.Ln;
|
||||
|
||||
str1 := "01234";str2 := "01234";
|
||||
StdLog.String(str1+" equals " + str2 + ":> ");StdLog.Bool(str1 = str2);StdLog.Ln;
|
||||
str2 := "0123";
|
||||
StdLog.String(str1+" equals " + str2 + ":> ");StdLog.Bool(str1 = str2);StdLog.Ln;
|
||||
StdLog.String(str1+" greater than " + str2 + ":> ");StdLog.Bool(str1 > str2);StdLog.Ln;
|
||||
StdLog.String(str1+" lower than " + str2 + ":> ");StdLog.Bool(str1 < str2);StdLog.Ln;
|
||||
END Do;
|
||||
|
||||
END StringComparision.
|
||||
50
Task/String-comparison/Go/string-comparison.go
Normal file
50
Task/String-comparison/Go/string-comparison.go
Normal file
|
|
@ -0,0 +1,50 @@
|
|||
package main
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"strings"
|
||||
)
|
||||
|
||||
func main() {
|
||||
// Go language string comparison operators:
|
||||
c := "cat"
|
||||
d := "dog"
|
||||
if c == d {
|
||||
fmt.Println(c, "is bytewise identical to", d)
|
||||
}
|
||||
if c != d {
|
||||
fmt.Println(c, "is bytewise different from", d)
|
||||
}
|
||||
if c > d {
|
||||
fmt.Println(c, "is lexically bytewise greater than", d)
|
||||
}
|
||||
if c < d {
|
||||
fmt.Println(c, "is lexically bytewise less than", d)
|
||||
}
|
||||
if c >= d {
|
||||
fmt.Println(c, "is lexically bytewise greater than or equal to", d)
|
||||
}
|
||||
if c <= d {
|
||||
fmt.Println(c, "is lexically bytewise less than or equal to", d)
|
||||
}
|
||||
// Go is strongly typed and will not directly compare a value of string
|
||||
// type to a value of numeric type.
|
||||
|
||||
// A case insensitive compare can be done with a function in the strings
|
||||
// package in the Go standard library:
|
||||
eqf := `when interpreted as UTF-8 and compared under Unicode
|
||||
simple case folding rules.`
|
||||
if strings.EqualFold(c, d) {
|
||||
fmt.Println(c, "equal to", d, eqf)
|
||||
} else {
|
||||
fmt.Println(c, "not equal to", d, eqf)
|
||||
}
|
||||
|
||||
// Seeing that the built in operators work bytewise and the library
|
||||
// case folding functions interpret UTF-8, you might then ask about
|
||||
// other equality and inequality tests that interpret UTF-8.
|
||||
// Functions for this are not in the Go standard library but are in
|
||||
// the Go "sub repository" at code.google.com/p/go. There is support
|
||||
// for Unicode normalization, collation tables, and locale sensitive
|
||||
// comparisons.
|
||||
}
|
||||
10
Task/String-comparison/Nimrod/string-comparison.nimrod
Normal file
10
Task/String-comparison/Nimrod/string-comparison.nimrod
Normal file
|
|
@ -0,0 +1,10 @@
|
|||
import strutils
|
||||
|
||||
var s1: string = "The quick brown"
|
||||
var s2: string = "The Quick Brown"
|
||||
echo("== : ", s1 == s2)
|
||||
echo("!= : ", s1 != s2)
|
||||
echo("< : ", s1 < s2)
|
||||
echo("<= : ", s1 <= s2)
|
||||
echo("> : ", s1 > s2)
|
||||
echo(">= : ", s1 >= s2)
|
||||
5
Task/String-comparison/Ruby/string-comparison.rb
Normal file
5
Task/String-comparison/Ruby/string-comparison.rb
Normal file
|
|
@ -0,0 +1,5 @@
|
|||
method_names = [:==,:!=, :>, :>=, :<, :<=, :<=>, :casecmp]
|
||||
[["YUP", "YUP"], ["YUP", "Yup"], ["bot","bat"],["zz", "aaa"]].each do |(str1, str2)|
|
||||
method_names.each{|m| print str1," ", m," ", str2,"\t", str1.send(m, str2),"\n"}
|
||||
puts
|
||||
end
|
||||
Loading…
Add table
Add a link
Reference in a new issue