To get the first 3 characters of a string in Swift, you can use the following code:
main.swift100 chars4 linesIn the code above, we create a string str and then use the prefix method to get the first three characters of the string. The result of the prefix method is a Substring, so we convert it to a String using the String initializer before printing it. The output of the code is "Hel".
gistlibby LogSnag