# Julia Notes Day2 -- string and collections

## Char and String

A `Char` value represents a single character

```julia
c = 'x'
d = Int('x') # 120
e = Char(120)  # 'x'
f = '\u2200' # '∀': Unicode U+2200 (category Sm: Symbol, math)
g = 'A' + 1 # 'B'
```

String literals are delimited by double quotes or triple double quotes (not single quotes).

```julia
s = "\u2200 x \u2203 y" # "∀ x ∃ y"
s *= "世界" # "∀ x ∃ y世界"
length(s) # 9
sizeof(s) # 17
s[end] # '界': Unicode U+754C (category Lo: Letter, other)

findfirst('界',s) # 15

# Sequential iteration is implemented by the iterate function. 
# The general for loop:
for c in s
    print(c*' ')
end
# ∀   x   ∃   y 世 界
```

> String literals are encoded using the UTF-8 encoding. UTF-8 is a variable-width encoding, meaning that not all characters are encoded in the same number of bytes ("code units"). In UTF-8, ASCII characters — i.e. those with code points less than 0x80 (128) – are encoded as they are in ASCII, using a single byte, while code points 0x80 and above are encoded using multiple bytes — up to four per character.
> 
> String indices in Julia refer to code units (= bytes for UTF-8), the fixed-width building blocks that are used to encode arbitrary characters (code points). This means that not every index into a `String` is necessarily a valid index for a character. If you index into a string at such an invalid byte index, an error is thrown

```julia
greet = "Hello"; whom = "world";

#Julia provides * for string concatenation
greet * ' ' * whom # "Hello world"

#interpolation into string literals using $
"$greet, $whom." # "Hello, world."

# triple-quoted strings are dedented to the level of the least-indented line.
str = """
           Hello,
           world.
         """
# "  Hello,\n  world.\n"

"1 + 2 = 3" == "1 + 2 = $(1 + 2)" # true

# repeat("A", 10)
'A'^10 # "AAAAAAAAAA"
"B"^10 # "BBBBBBBBBB"
"BA"^10 # "BABABABABABABABABABA"
```

## Range and Vector

```julia
V = [i/2 for i in 1:10]

# Comprehensions can also be written without the enclosing square brackets, 
# producing an object known as a generator.
sum(1/n^2 for n=1:1000)

# convert a range to a vector by using the collect function.
vec = collect(1:2:7)
println(vec)  # Output: [1, 3, 5, 7]
```

## Matrix

```julia
A = [1 2; 3 4] 
#= 2×2 Matrix{Int64}:
 1  2
 3  4
=#
B = A*A*A
#= 2×2 Matrix{Int64}:
 37   54
 81  118
=#
B == A^3 # true

C = A * 3
C == 3A  # true

sin.(A)
#= 2×2 Matrix{Float64}:
 0.841471   0.909297
 0.14112   -0.756802
=#

sin(A)
#= 2×2 Matrix{Float64}:
 -0.465581  -0.148424
 -0.222637  -0.688218
=#

A*[1,2]
#= 2-element Vector{Int64}:
  5
 11
=#
```

## Dict

```julia
Dict("A"=>1, "B"=>2)
#= Dict{String, Int64} with 2 entries:
  "B" => 2
  "A" => 1
=#
```

## List of functions of Collections

> * [Base.iterate — Function](https://docs.julialang.org/en/v1/base/collections/#Base.iterate)
>     
> * [Base.IteratorSize — Type](https://docs.julialang.org/en/v1/base/collections/#Base.IteratorSize)
>     
> * [Base.IteratorEltype — Type](https://docs.julialang.org/en/v1/base/collections/#Base.IteratorEltype)
>     
> * [Base.AbstractRange — Type](https://docs.julialang.org/en/v1/base/collections/#Base.AbstractRange)
>     
> * [Base.OrdinalRange — Type](https://docs.julialang.org/en/v1/base/collections/#Base.OrdinalRange)
>     
> * [Base.AbstractUnitRange — Type](https://docs.julialang.org/en/v1/base/collections/#Base.AbstractUnitRange)
>     
> * [Base.StepRange — Type](https://docs.julialang.org/en/v1/base/collections/#Base.StepRange)
>     
> * [Base.UnitRange — Type](https://docs.julialang.org/en/v1/base/collections/#Base.UnitRange)
>     
> * [Base.LinRange — Type](https://docs.julialang.org/en/v1/base/collections/#Base.LinRange)
>     
> * [Base.isempty — Function](https://docs.julialang.org/en/v1/base/collections/#Base.isempty)
>     
> * [Base.empty! — Function](https://docs.julialang.org/en/v1/base/collections/#Base.empty!)
>     
> * [Base.length — Function](https://docs.julialang.org/en/v1/base/collections/#Base.length)
>     
> * [Base.checked\_length — Function](https://docs.julialang.org/en/v1/base/collections/#Base.checked_length)
>     
> * [Base.in — Function](https://docs.julialang.org/en/v1/base/collections/#Base.in)
>     
> * [Base.:∉ — Function](https://docs.julialang.org/en/v1/base/collections/#Base.:%E2%88%89)
>     
> * [Base.eltype — Function](https://docs.julialang.org/en/v1/base/collections/#Base.eltype)
>     
> * [Base.indexin — Function](https://docs.julialang.org/en/v1/base/collections/#Base.indexin)
>     
> * [Base.unique — Function](https://docs.julialang.org/en/v1/base/collections/#Base.unique)
>     
> * [Base.unique! — Function](https://docs.julialang.org/en/v1/base/collections/#Base.unique!)
>     
> * [Base.allunique — Function](https://docs.julialang.org/en/v1/base/collections/#Base.allunique)
>     
> * [Base.allequal — Function](https://docs.julialang.org/en/v1/base/collections/#Base.allequal)
>     
> * [Base.reduce — Method](https://docs.julialang.org/en/v1/base/collections/#Base.reduce-Tuple{Any,20%Any})
>     
> * [Base.reduce — Method](https://docs.julialang.org/en/v1/base/collections/#Base.reduce-Tuple{Any,20%AbstractArray})
>     
> * [Base.foldl — Method](https://docs.julialang.org/en/v1/base/collections/#Base.foldl-Tuple{Any,20%Any})
>     
> * [Base.foldr — Method](https://docs.julialang.org/en/v1/base/collections/#Base.foldr-Tuple{Any,20%Any})
>     
> * [Base.maximum — Function](https://docs.julialang.org/en/v1/base/collections/#Base.maximum)
>     
> * [Base.maximum! — Function](https://docs.julialang.org/en/v1/base/collections/#Base.maximum!)
>     
> * [Base.minimum — Function](https://docs.julialang.org/en/v1/base/collections/#Base.minimum)
>     
> * [Base.minimum! — Function](https://docs.julialang.org/en/v1/base/collections/#Base.minimum!)
>     
> * [Base.extrema — Function](https://docs.julialang.org/en/v1/base/collections/#Base.extrema)
>     
> * [Base.extrema! — Function](https://docs.julialang.org/en/v1/base/collections/#Base.extrema!)
>     
> * [Base.argmax — Function](https://docs.julialang.org/en/v1/base/collections/#Base.argmax)
>     
> * [Base.argmin — Function](https://docs.julialang.org/en/v1/base/collections/#Base.argmin)
>     
> * [Base.findmax — Function](https://docs.julialang.org/en/v1/base/collections/#Base.findmax)
>     
> * [Base.findmin — Function](https://docs.julialang.org/en/v1/base/collections/#Base.findmin)
>     
> * [Base.findmax! — Function](https://docs.julialang.org/en/v1/base/collections/#Base.findmax!)
>     
> * [Base.findmin! — Function](https://docs.julialang.org/en/v1/base/collections/#Base.findmin!)
>     
> * [Base.sum — Function](https://docs.julialang.org/en/v1/base/collections/#Base.sum)
>     
> * [Base.sum! — Function](https://docs.julialang.org/en/v1/base/collections/#Base.sum!)
>     
> * [Base.prod — Function](https://docs.julialang.org/en/v1/base/collections/#Base.prod)
>     
> * [Base.prod! — Function](https://docs.julialang.org/en/v1/base/collections/#Base.prod!)
>     
> * [Base.any — Method](https://docs.julialang.org/en/v1/base/collections/#Base.any-Tuple%7BAny%7D)
>     
> * [Base.any — Method](https://docs.julialang.org/en/v1/base/collections/#Base.any-Tuple{AbstractArray,20%Any})
>     
> * [Base.any! — Function](https://docs.julialang.org/en/v1/base/collections/#Base.any!)
>     
> * [Base.all — Method](https://docs.julialang.org/en/v1/base/collections/#Base.all-Tuple%7BAny%7D)
>     
> * [Base.all — Method](https://docs.julialang.org/en/v1/base/collections/#Base.all-Tuple{AbstractArray,20%Any})
>     
> * [Base.all! — Function](https://docs.julialang.org/en/v1/base/collections/#Base.all!)
>     
> * [Base.count — Function](https://docs.julialang.org/en/v1/base/collections/#Base.count)
>     
> * [Base.foreach — Function](https://docs.julialang.org/en/v1/base/collections/#Base.foreach)
>     
> * [Base.map — Function](https://docs.julialang.org/en/v1/base/collections/#Base.map)
>     
> * [Base.map! — Function](https://docs.julialang.org/en/v1/base/collections/#Base.map!)
>     
> * [Base.mapreduce — Method](https://docs.julialang.org/en/v1/base/collections/#Base.mapreduce-Tuple{Any,%20Any,%20Any})
>     
> * [Base.mapfoldl — Method](https://docs.julialang.org/en/v1/base/collections/#Base.mapfoldl-Tuple{Any,%20Any,%20Any})
>     
> * [Base.mapfoldr — Method](https://docs.julialang.org/en/v1/base/collections/#Base.mapfoldr-Tuple{Any,%20Any,%20Any})
>     
> * [Base.first — Function](https://docs.julialang.org/en/v1/base/collections/#Base.first)
>     
> * [Base.last — Function](https://docs.julialang.org/en/v1/base/collections/#Base.last)
>     
> * [Base.front — Function](https://docs.julialang.org/en/v1/base/collections/#Base.front)
>     
> * [Base.tail — Function](https://docs.julialang.org/en/v1/base/collections/#Base.tail)
>     
> * [Base.step — Function](https://docs.julialang.org/en/v1/base/collections/#Base.step)
>     
> * [Base.collect — Method](https://docs.julialang.org/en/v1/base/collections/#Base.collect-Tuple%7BAny%7D)
>     
> * [Base.collect — Method](https://docs.julialang.org/en/v1/base/collections/#Base.collect-Tuple{Type,%20Any})
>     
> * [Base.filter — Function](https://docs.julialang.org/en/v1/base/collections/#Base.filter)
>     
> * [Base.filter! — Function](https://docs.julialang.org/en/v1/base/collections/#Base.filter!)
>     
> * [Base.replace — Method](https://docs.julialang.org/en/v1/base/collections/#Base.replace-Tuple{Any,20%Vararg{Pair}})
>     
> * [Base.replace — Method](https://docs.julialang.org/en/v1/base/collections/#Base.replace-Tuple{Union{Function,%20Type},%20Any})
>     
> * [Base.replace! — Function](https://docs.julialang.org/en/v1/base/collections/#Base.replace!)
>     
> * [Base.rest — Function](https://docs.julialang.org/en/v1/base/collections/#Base.rest)
>     
> * [Base.split\_rest — Function](https://docs.julialang.org/en/v1/base/collections/#Base.split_rest)
>     
> * [Base.getindex — Function](https://docs.julialang.org/en/v1/base/collections/#Base.getindex)
>     
> * [Base.setindex! — Function](https://docs.julialang.org/en/v1/base/collections/#Base.setindex!)
>     
> * [Base.firstindex — Function](https://docs.julialang.org/en/v1/base/collections/#Base.firstindex)
>     
> * [Base.lastindex — Function](https://docs.julialang.org/en/v1/base/collections/#Base.lastindex)
>     
> * [Base.AbstractDict — Type](https://docs.julialang.org/en/v1/base/collections/#Base.AbstractDict)
>     
> * [Base.Dict — Type](https://docs.julialang.org/en/v1/base/collections/#Base.Dict)
>     
> * [Base.IdDict — Type](https://docs.julialang.org/en/v1/base/collections/#Base.IdDict)
>     
> * [Base.WeakKeyDict — Type](https://docs.julialang.org/en/v1/base/collections/#Base.WeakKeyDict)
>     
> * [Base.ImmutableDict — Type](https://docs.julialang.org/en/v1/base/collections/#Base.ImmutableDict)
>     
> * [Base.haskey — Function](https://docs.julialang.org/en/v1/base/collections/#Base.haskey)
>     
> * [Base.get — Function](https://docs.julialang.org/en/v1/base/collections/#Base.get)
>     
> * [Base.get! — Function](https://docs.julialang.org/en/v1/base/collections/#Base.get!)
>     
> * [Base.getkey — Function](https://docs.julialang.org/en/v1/base/collections/#Base.getkey)
>     
> * [Base.delete! — Function](https://docs.julialang.org/en/v1/base/collections/#Base.delete!)
>     
> * [Base.pop! — Method](https://docs.julialang.org/en/v1/base/collections/#Base.pop!-Tuple{Any,%20Any,%20Any})
>     
> * [Base.keys — Function](https://docs.julialang.org/en/v1/base/collections/#Base.keys)
>     
> * [Base.values — Function](https://docs.julialang.org/en/v1/base/collections/#Base.values)
>     
> * [Base.pairs — Function](https://docs.julialang.org/en/v1/base/collections/#Base.pairs)
>     
> * [Base.merge — Function](https://docs.julialang.org/en/v1/base/collections/#Base.merge)
>     
> * [Base.mergewith — Function](https://docs.julialang.org/en/v1/base/collections/#Base.mergewith)
>     
> * [Base.merge! — Function](https://docs.julialang.org/en/v1/base/collections/#Base.merge!)
>     
> * [Base.mergewith! — Function](https://docs.julialang.org/en/v1/base/collections/#Base.mergewith!)
>     
> * [Base.sizehint! — Function](https://docs.julialang.org/en/v1/base/collections/#Base.sizehint!)
>     
> * [Base.keytype — Function](https://docs.julialang.org/en/v1/base/collections/#Base.keytype)
>     
> * [Base.valtype — Function](https://docs.julialang.org/en/v1/base/collections/#Base.valtype)
>     
> * [Base.AbstractSet — Type](https://docs.julialang.org/en/v1/base/collections/#Base.AbstractSet)
>     
> * [Base.Set — Type](https://docs.julialang.org/en/v1/base/collections/#Base.Set)
>     
> * [Base.BitSet — Type](https://docs.julialang.org/en/v1/base/collections/#Base.BitSet)
>     
> * [Base.union — Function](https://docs.julialang.org/en/v1/base/collections/#Base.union)
>     
> * [Base.union! — Function](https://docs.julialang.org/en/v1/base/collections/#Base.union!)
>     
> * [Base.intersect — Function](https://docs.julialang.org/en/v1/base/collections/#Base.intersect)
>     
> * [Base.setdiff — Function](https://docs.julialang.org/en/v1/base/collections/#Base.setdiff)
>     
> * [Base.setdiff! — Function](https://docs.julialang.org/en/v1/base/collections/#Base.setdiff!)
>     
> * [Base.symdiff — Function](https://docs.julialang.org/en/v1/base/collections/#Base.symdiff)
>     
> * [Base.symdiff! — Function](https://docs.julialang.org/en/v1/base/collections/#Base.symdiff!)
>     
> * [Base.intersect! — Function](https://docs.julialang.org/en/v1/base/collections/#Base.intersect!)
>     
> * [Base.issubset — Function](https://docs.julialang.org/en/v1/base/collections/#Base.issubset)
>     
> * [Base.:⊈ — Function](https://docs.julialang.org/en/v1/base/collections/#Base.:%E2%8A%88)
>     
> * [Base.:⊊ — Function](https://docs.julialang.org/en/v1/base/collections/#Base.:%E2%8A%8A)
>     
> * [Base.issetequal — Function](https://docs.julialang.org/en/v1/base/collections/#Base.issetequal)
>     
> * [Base.isdisjoint — Function](https://docs.julialang.org/en/v1/base/collections/#Base.isdisjoint)
>     
> * [Base.push! — Function](https://docs.julialang.org/en/v1/base/collections/#Base.push!)
>     
> * [Base.pop! — Function](https://docs.julialang.org/en/v1/base/collections/#Base.pop!)
>     
> * [Base.popat! — Function](https://docs.julialang.org/en/v1/base/collections/#Base.popat!)
>     
> * [Base.pushfirst! — Function](https://docs.julialang.org/en/v1/base/collections/#Base.pushfirst!)
>     
> * [Base.popfirst! — Function](https://docs.julialang.org/en/v1/base/collections/#Base.popfirst!)
>     
> * [Base.insert! — Function](https://docs.julialang.org/en/v1/base/collections/#Base.insert!)
>     
> * [Base.deleteat! — Function](https://docs.julialang.org/en/v1/base/collections/#Base.deleteat!)
>     
> * [Base.keepat! — Function](https://docs.julialang.org/en/v1/base/collections/#Base.keepat!)
>     
> * [Base.splice! — Function](https://docs.julialang.org/en/v1/base/collections/#Base.splice!)
>     
> * [Base.resize! — Function](https://docs.julialang.org/en/v1/base/collections/#Base.resize!)
>     
> * [Base.append! — Function](https://docs.julialang.org/en/v1/base/collections/#Base.append!)
>     
> * [Base.prepend! — Function](https://docs.julialang.org/en/v1/base/collections/#Base.prepend!)
>     
> * [Core.Pair — Type](https://docs.julialang.org/en/v1/base/collections/#Core.Pair)
>     
> * [Base.Pairs — Type](https://docs.julialang.org/en/v1/base/collections/#Base.Pairs)
>
