split a string by the letter h in swift

You can split a string by a specific character (in this case, "h") using the components(separatedBy:) method in Swift. Here's an example:

main.swift
let myString = "hello world"
let myArray = myString.components(separatedBy: "h")
print(myArray) // ["", "ello world"]
118 chars
4 lines

In this case, the string is split into an array at every occurrence of the letter "h". The resulting array has two elements, representing the two parts of the original string before and after the split character.

gistlibby LogSnag