Data update
This commit is contained in:
parent
8e4e15fa56
commit
72eb4943cb
1853 changed files with 35514 additions and 9441 deletions
48
Task/Binary-strings/Sidef/binary-strings.sidef
Normal file
48
Task/Binary-strings/Sidef/binary-strings.sidef
Normal file
|
|
@ -0,0 +1,48 @@
|
|||
# string creation
|
||||
var x = "hello world"
|
||||
|
||||
# string destruction
|
||||
x = nil
|
||||
|
||||
# string assignment with a null byte
|
||||
x = "a\0b"
|
||||
say x.length # ==> 3
|
||||
|
||||
# string comparison
|
||||
if (x == "hello") {
|
||||
say "equal"
|
||||
} else {
|
||||
say "not equal"
|
||||
}
|
||||
|
||||
var y = 'bc'
|
||||
if (x < y) {
|
||||
say "#{x} is lexicographically less than #{y}"
|
||||
}
|
||||
|
||||
# string cloning
|
||||
var xx = x.clone
|
||||
say (x == xx) # true, same length and content
|
||||
say (x.refaddr == xx.refaddr) # false, different objects
|
||||
|
||||
# check if empty
|
||||
if (x.is_empty) {
|
||||
say "is empty"
|
||||
}
|
||||
|
||||
# append a byte
|
||||
x += "\07"
|
||||
say x.dump #=> "a\0b\a"
|
||||
|
||||
# substring
|
||||
say x.substr(0, -1).dump #=> "a\0b"
|
||||
|
||||
# replace bytes
|
||||
say "hello world".tr("l", "L")
|
||||
|
||||
# join strings
|
||||
var a = "hel"
|
||||
var b = "lo w"
|
||||
var c = "orld"
|
||||
var d = (a + b + c)
|
||||
say d
|
||||
Loading…
Add table
Add a link
Reference in a new issue