3

I have the following problem:

I want to compare if one string contains "Schreibe etwas..."

I solved it with the following code:

selectedText = postTextView.text!
let isText = selectedText

if isText != "Schreibe etwas..." {
    shareButton.isEnabled = true
    abortButton.isEnabled = true
}

But its not working. How to solve this problem?

Thanks in advance for your help!

Shehata Gamal
  • 98,760
  • 8
  • 65
  • 87
jo1995
  • 414
  • 1
  • 5
  • 14

3 Answers3

2

You can try

if !isText.contains("Schreibe etwas...") {
    shareButton.isEnabled = true
    abortButton.isEnabled = true
}
Shehata Gamal
  • 98,760
  • 8
  • 65
  • 87
1
let myString =  isText.absoluteString
if myString.range(of:"Schreibe etwas") != nil { 

//do some thing

}
amin
  • 313
  • 1
  • 10
0

use this code to compare two String

  var a : String = "Schreibe etwas..."
  var b  : String = "Schreibe etwas..."

  if(a.caseInsensitiveCompare(b) == .orderedSame){
      print("string is Same")
  }