How to remove the first word from string in Swift

1 Answer

0 votes
import Foundation

func trimFirstWord(from input: String) -> String {
    if let range = input.rangeOfCharacter(from: CharacterSet(charactersIn: " \t")) {
        return String(input[range.upperBound...])
    } else {
        return input // No space or tab found
    }
}

let s = "c++ c c# java php swift"

let result = trimFirstWord(from: s)

print(result)



/*
run:

c c# java php swift

*/

 



answered Sep 25, 2025 by avibootz
...