Swift: Reverse a string word by word
By somaria
2022-10-28
import Cocoa //Swift define a string let str = "A Quick Brown Fox Jumps Over The Lazy Dog" //print the string print(str) //reverse the string word by word let reversed = str.components(separatedBy: " ").reversed().joined(separator: " ") //print the reversed string print(reversed)

Output

A Quick Brown Fox Jumps Over The Lazy Dog

Dog Lazy The Over Jumps Fox Brown Quick A