-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,712
  • 1
  • 26
  • 28
Manvir Singh
  • 119
  • 1
  • 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
  • 73,141
  • 39
  • 203
  • 288
0
if "test".contains("es") {
    //...                
}
ovo
  • 1,578
  • 11
  • 24
  • 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