typestar

Joining strings in Mojo

join glues a list of strings together with a separator.

def main():
    var steps: List[String] = ["read", "type", "repeat"]
    print(", ".join(steps))
    print(" -> ".join(steps))
    var parts: List[String] = ["usr", "local", "bin"]
    print("/" + "/".join(parts))

How it works

  1. The separator is the string you call join on.
  2. steps is typed List[String], which is what join expects.
  3. Any separator works, including a path slash.

Keywords and builtins used here

The run, in numbers

Lines
6
Characters to type
193
Tokens
79
Three-star pace
80 tpm

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

Type this snippet

Step 3 of 5 in Strings, step 20 of 26 in Language basics.

← Previous Next →