-1

I want to find the rangeOfString for multiple items and have tried using an array with a for-in loop, however this just cycles to the last term of the array and uses that for the rangeOfString. Is it possible to use an array with rangeOfString so it searches all terms concurrently or do I have to write the rangeOfString individually for each term.

while true {
    let attempts = ["goodmorning","goodbye", "hello", "hi"]
    for attempt in attempts{

         tru = attempt




    let range = text.rangeOfString(tru, options: [], range: searchRange)
Lorenzo
  • 3,293
  • 4
  • 29
  • 56
SandySunday
  • 41
  • 1
  • 2
  • 1
    Please post your code, sounds like you might have an incorrectly stated for loop – rudd Oct 06 '15 at 21:20
  • 1
    Possible duplicate of [Number of occurrences of a substring in an NSString?](http://stackoverflow.com/questions/2166809/number-of-occurrences-of-a-substring-in-an-nsstring) – chedabob Oct 06 '15 at 21:40

1 Answers1

0

Try this:

let attempts = ["goodmorning","goodbye", "hello", "hi"]
for attempt in attempts {
    if text.rangeOfString(attempt) != nil {
        print("found \(attempt)")
    }
}
haluzak
  • 1,133
  • 3
  • 17
  • 31