Introducere în șiruri de caractere

Introducere în Julia

James Fulton

Climate informatics researcher

Șiruri de caractere

# Strings are surrounded by " "
name = "Jane" # Cannot use 'Jane'


# Strings can be any length book = "It is a truth universally acknowledged, ..."
println(name)
println(book)
Jane

It is a truth universally acknowledged, ...
Introducere în Julia

Ghilimele triple

# Triple quotes 
poem = """Beware the Jabberwock, my son!

      The jaws that bite, the claws that catch!"""


println(poem)
Beware the Jabberwock, my son!

The jaws that bite, the claws that catch!
Introducere în Julia

Ghilimele triple

greeting = """ " Well hello there " """

println(greeting)
 " Well hello there " 
greeting = " " Well hello there " "


ERROR: syntax: ...
Introducere în Julia

Concatenarea șirurilor

name = "James"

greeting = "Well hello there, "


# Concatenate two strings
println(greeting*name)
Well hello there, James
Introducere în Julia

Interpolarea șirurilor

name = "James"


# Interpolate with $ symbol greeting = "Well hello there, $name"
println(greeting)
Well hello there, James
Introducere în Julia

Interpolarea șirurilor

x_int = 10


# Insert integer into string println("The value is $x_int")
The value is 10
x_float = 1.0


# Insert float into string println("The value is $x_float")
The value is 1.0
x_bool = true


# Insert boolean into string println("The value is $x_bool")
The value is true
x_char = 'A'


# Insert character into string println("The value is $x_char")
The value is A
Introducere în Julia

Interpolarea șirurilor

x = 10
y = 3


# Insert x*y into string println("The product of x and y is $(x*y)")
The product of x and y is 30
Introducere în Julia

Interpolarea șirurilor

x = 10
y = 3


# Insert x*y into string println("The product of x and y is \$(x*y)")
The product of x and y is $(x*y)
Introducere în Julia

Indexarea șirurilor

# Customer's seat
seat = "E5"


# Select character row = seat[1] # this returns 'E'

println(row)
println(typeof(row))
E

Char
Introducere în Julia

Indexarea șirurilor

# Customer's seat
seat = "E5"

# Select characters
row = seat[1]       # this returns 'E'
number = seat[2]    # this returns '5'


println("Your seat is in row $row, seat number $number.")
Your seat is in row E, seat number 5.
Introducere în Julia

Indexarea șirurilor

# Customer's seat
seat = "E5"

# Select characters
row = seat[1]       # this returns 'E'
number = seat[end]  # this returns '5'

println("Your seat is in row $row, seat number $number.")
Your seat is in row E, seat number 5.
Introducere în Julia

Indexarea șirurilor

# Customer's seat
seat = "E5"

# Select characters
row = seat[end-1]   # this returns 'E'
number = seat[end]  # this returns '5'

println("Your seat is in row $row, seat number $number.")
Your seat is in row E, seat number 5.
Introducere în Julia

Secționarea șirurilor




receipt = "08:30 - coffee - \$3.50" println(receipt)
08:30 - coffee - $3.50
Introducere în Julia

Secționarea șirurilor

# Index position:
#          12345...
receipt = "08:30 - coffee - \$3.50"


time = receipt[1:5] # Select first 5 characters
println(time)
08:30

Introducere în Julia

Secționarea șirurilor

# Index position from end:
#                            4321end
receipt = "08:30 - coffee - \$3.50"

time = receipt[1:5]         # Select first 5 characters

price = receipt[end-4:end] # Select last 5 characters
println(time)
println(price)
08:30

$3.50
Introducere în Julia

Să exersăm!

Introducere în Julia

Preparing Video For Download...