Strings In Depth15 / 18
Up next

Substring

let s = "hello world"
// prefix returns a Substring sharing s's storage
let head: Substring = s.prefix(5)
print(head)
// build an independent String when you need to store it
let owned = String(head)
print(owned)
What you're solving

prefix/suffix give a Substring