typestar

Strings in Julia

Interpolation with $, concatenation with *, repetition with ^.

target = "Saturn"
altitude = 38.5

# $name splices a value; $(expr) splices any expression.
println("$target sits at $altitude degrees")
println("Rises past 45? $(altitude + 10 > 45)")

# Strings concatenate with * and repeat with ^.
banner = "-"^12
println(banner * " LOG " * banner)

# Triple quotes span lines and keep the breaks.
note = """
Seeing: steady
Dew: forming on the corrector"""
println(note)

How it works

  1. $target splices a value; $(altitude + 10 > 45) any expression.
  2. Strings multiply: "-"^12 repeats, * concatenates.
  3. Triple quotes span lines and keep the breaks.

The run, in numbers

Lines
16
Characters to type
406
Tokens
61
Three-star pace
70 tpm

At the three-star pace of 70 tokens a minute, this run takes about 52 seconds.

Type this snippet

Step 3 of 3 in Values, step 3 of 27 in Language basics.

← Previous Next →

Strings in other languages