How to get the second word of a string in Swift

1 Answer

0 votes
import Foundation

let sentence = "Swift programming language for iOS, iPadOS, macOS, tvOS, and watchOS"

let words = sentence.split(separator: " ")

let secondWord = words.count > 1 ? String(words[1]) : "No second word"

print(secondWord)



/*
run:

programming

*/

 



answered Dec 19, 2024 by avibootz
...