title: After appending a character to the end of my string, an unwanted space is added. How do I remove this?
body: <p>In the below textView function, I append the '#' character to the end of my string every time the user presses the spacebar. However, an unwanted space comes after the appended character. I've used functions to remove whitespaces at the end of the string but those don't help. Furthermore, I also tried to remove the last character of my string using removeLast() but that just removes the '#' character itself. Please help! I'm using swift 4.2.</p>
  
  <pre><code>func textView(_ textView: UITextView, shouldChangeTextIn range: NSRange, replacementText text: String) -&gt; Bool {
      if text == " " {
          textView.text.append(("#"))
          //textView.text.removeLast()
      }
      if text == "\n" {
          textView.resignFirstResponder()
          return false
      }
      return true
  }
  </code></pre>