I\'m very new to Swift; I\'ve spent the morning reading StackOverflow and trying many strategies, in vain, to accomplish the following:
I have a string, say \"12345 is
With Swift 5 you can use:
myStr.prefix(upTo: myStr.firstIndex(of: " ") ?? myStr.startIndex)
You may need to cast it back to String (String(myStr.prefix(upTo: myStr.firstIndex(of: " ") ?? myStr.startIndex))) since it returns a Substring
String(myStr.prefix(upTo: myStr.firstIndex(of: " ") ?? myStr.startIndex))