RosettaCodeData/Task/Substring/Elixir/substring.elixir

13 lines
398 B
Text
Raw Permalink Normal View History

2015-11-18 06:14:39 +00:00
s = "abcdefgh"
String.slice(s, 2, 3) #=> "cde"
String.slice(s, 1..3) #=> "bcd"
String.slice(s, -3, 2) #=> "fg"
String.slice(s, 3..-1) #=> "defgh"
2016-12-05 22:15:40 +01:00
# UTF-8
s = "αβγδεζηθ"
String.slice(s, 2, 3) #=> "γδε"
String.slice(s, 1..3) #=> "βγδ"
String.slice(s, -3, 2) #=> "ζη"
String.slice(s, 3..-1) #=> "δεζηθ"