4

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!

Sh_Khan
  • 93,445
  • 7
  • 57
  • 76
jo1995
  • 408
  • 1
  • 5
  • 13

3 Answers3

2

You can try

if !isText.contains("Schreibe etwas...") {
    shareButton.isEnabled = true
    abortButton.isEnabled = true
}
Sh_Khan
  • 93,445
  • 7
  • 57
  • 76
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")
  }