Jump to content

Binary strings: Difference between revisions

Added Elixir
(→‎{{header|Perl 6}}: various updates for 6.c)
(Added Elixir)
Line 168:
7th byte in CPU word is: w
</pre>
 
=={{header|AWK}}==
<lang AWK>#!/usr/bin/awk -f
Line 216 ⟶ 217:
d=<123 abc @456 789>
</pre>
 
 
=={{header|BASIC}}==
Line 491:
}
}</lang>
 
 
=={{header|Common Lisp}}==
Line 616 ⟶ 615:
pStr + '.' + pAux:>First string.Second String
</pre>
 
=={{header|D}}==
<lang d>void main() /*@safe*/ {
Line 731:
# value: [1, 2, 3, -127, 2, 3].diverge()</lang>
</li></ol>
 
=={{header|Elixir}}==
Note: Elixir data types are immutable.
<lang elixir># String creation
x = "hello world"
 
# String destruction
x = nil
 
# String assignment with a null byte
x = "a\0b"
IO.inspect x #=> <<97, 0, 98>>
IO.puts String.length(x) #=> 3
 
# string comparison
if x == "hello" do
IO.puts "equal"
else
IO.puts "not equal" #=> not equal
end
y = "bc"
if x < y do
IO.puts "#{x} is lexicographically less than #{y}" #=> a b is lexicographically less than bc
end
 
# string cloning
xx = x
IO.puts x == xx #=> true (same length and content)
 
# check if empty
if x=="" do
IO.puts "is empty"
end
if String.length(x)==0 do
IO.puts "is empty"
end
 
# append a byte
IO.puts x <> "\07" #=> a b 7
IO.inspect x <> "\07" #=> <<97, 0, 98, 0, 55>>
 
# substring
IO.puts String.slice("elixir", 1..3) #=> lix
IO.puts String.slice("elixir", 2, 3) #=> ixi
 
# replace bytes
IO.puts String.replace("a,b,c", ",", "-") #=> a-b-c
 
# string interpolation
a = "abc"
n = 100
IO.puts "#{a} : #{n}" #=> abc : 100
 
# join strings
a = "hel"
b = "lo w"
c = "orld"
IO.puts a <> b <> c #=> hello world</lang>
 
=={{header|Erlang}}==
Line 2,339 ⟶ 2,397:
See a + b + c
</lang>
 
 
=={{header|Ruby}}==
Line 2,425 ⟶ 2,482:
s$ = "See " + "you " + "later."
print s$</lang>
 
 
 
=={{header|Rust}}==
Anonymous user
Cookies help us deliver our services. By using our services, you agree to our use of cookies.