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
- The separator is the string you call
joinon. stepsis typedList[String], which is whatjoinexpects.- Any separator works, including a path slash.
Keywords and builtins used here
ListStringdefmainprintvar
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.
Step 3 of 5 in Strings, step 20 of 26 in Language basics.