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!

1
  • What is isText ? BTW, this is right way to compare string. Commented Dec 19, 2018 at 12:48

3 Answers 3

2

You can try

if !isText.contains("Schreibe etwas...") {
    shareButton.isEnabled = true
    abortButton.isEnabled = true
}
Sign up to request clarification or add additional context in comments.

5 Comments

I think the "..." is not part of his text.
but the op set it look to the comparison
Thanks for your answer! but I want to check if it Doesn't contains "Schreibe etwas..."
simply put ! see edit .........
Look at this question for my full question: [stackoverflow.com/questions/53850023/… Thanks in advance for your help!
1
let myString =  isText.absoluteString
if myString.range(of:"Schreibe etwas") != nil { 

//do some thing

}

Comments

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")
  }

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.