-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathstrings.jl
51 lines (37 loc) · 1.25 KB
/
strings.jl
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
using Printf
function string_examples()
println("--------------------------------------")
println("String examples")
println("Strings have to be surrounded by double-quotes")
s1 = "Just some random words\n"
println(s1)
println("Size of string")
println(length(s1))
println("The 1st index is at 1 (NOT ZERO INDEXED!)")
println(s1[1])
println("Get last character")
println(s1[end])
println("Get a range")
println(s1[1:4])
println("Concatenation")
s2 = string("Yukiteru", " Amano")
println(s2)
println("You can also concatenate strings with the * symbol")
println("Yuno" * " Gasai")
println("Interpolation (like using {0} is C#)")
i3 = 2
i4 = 3
println("$i3 + $i4 = $(i3 + i4)")
println("Multiline strings are surrounded by triple-quotes. Note the output includes the new-lines!")
s3 = """I
have
many
lines"""
println(s3)
println("String comparisons with == > < !=")
println("Takao" > "Hiyama")
println("Find index for character (note the result is one-indexed, so index of 'i' in 'Keigo' will be 3 not 2)")
println(findfirst(isequal('i'), "Keigo"))
println("Find a substring")
println(occursin("key", "monkey"))
end