import Foundation
func removeLastWord(from input: String) -> String {
if let lastSpaceRange = input.range(of: " ", options: .backwards) {
return String(input[..<lastSpaceRange.lowerBound])
} else {
return input // No space found, return original
}
}
let s = "c# swift c c++ java"
let result = removeLastWord(from: s)
print(result)
/*
run:
c# swift c c++
*/