-2

I want to compare 2 strings like if 1 string contain some part of other then it will true for example

if "test" == "es"
{
}

I want true in above case

Note - strings maybe of any length

garyh
  • 2,782
  • 1
  • 26
  • 28
Manvir Singh
  • 129
  • 2
  • 11

2 Answers2

2

Don't use NSString in Swift. Use String (which is also the default when you create Strings).

Anyway, contains() is what you're looking for.

if "test".contains("es") {
    // this will run
}
Fogmeister
  • 76,236
  • 42
  • 207
  • 306
0
if "test".contains("es") {
    //...                
}
ovo
  • 1,904
  • 13
  • 26
  • While this code may answer the question, providing additional context regarding how and/or why it solves the problem would improve the answer's long-term value. – Badacadabra Jun 16 '17 at 14:16