0

I did not find any clues on how to achieve this in Swift 5.

The string.index(of) requires only a character and not a word. What i need is to extract the substring at position from and to without using hard coded numbers to be used for offset.

is NSRange the solution for this? I wish to do something like

string[string.startIndex...<string.index(of: fromWord)] But this results in an error but gives the error message annot convert value of type 'String' to expected argument type 'String.Element' (aka 'Character').

let string = "Hello world. This is a statement."
print(String(string[string.startIndex..<string.index(of: "This is a statement"]))
chitgoks
  • 311
  • 2
  • 6
  • 17

0 Answers0