How to get substring from the second word in Swift

1 Answer

0 votes
func substringFromSecondWord(value: String) -> String {
    if let space = value.firstIndex(of: " ") {
        return String(value[value.index(after: space)..<value.endIndex])
    }
    return ""
}

print(substringFromSecondWord(value: "swift java c++ c python"))

  
  
   
/*
run:
 
java c++ c python
   
*/

 



answered Nov 9, 2020 by avibootz
...