-3

image

I want add the " " symbols to my text data. text data is getting from textview. I want remove the " " symbols from optional text. optional text is getting from text filed, how to remove and how to add the "" symbols in swift.......

naga
  • 397
  • 2
  • 12
  • 26
  • 1
    search for optionals swift in google – J. Doe Sep 22 '17 at 20:30
  • 1
    Please read [Swift Language Guide: The Basics](https://developer.apple.com/library/content/documentation/Swift/Conceptual/Swift_Programming_Language/TheBasics.html) – vadian Sep 22 '17 at 20:32
  • https://stackoverflow.com/questions/25591241/swift-remove-character-from-string – Vini App Sep 22 '17 at 21:12

1 Answers1

1

The problem is that the string you are trying to log is typed as an optional (String?) rather than just a String. You need to unwrap it before logging it.

You can either use if let:

if let string = maybeString {
    print(string)
}

Or (and this is what I prefer), you can use the ?? operator to provide a placeholder value to print in the case of the string being nil:

print(string ?? "(nil)")
Charles Srstka
  • 16,665
  • 3
  • 34
  • 60
  • I have compare the both values – naga Sep 22 '17 at 20:35
  • textdata for RFID device and optional values from my json id I have to compare Both datas like let dataval = kid.cardNo if self.textdata == dataval but its not working because of this symbols if I can specified like self.textdata = "71beda1d" its working – naga Sep 22 '17 at 20:36
  • @naga I'm sorry, I can't understand what you're saying. – Charles Srstka Sep 22 '17 at 22:14
  • tq for support I can resolve my issue with convert to string its working fine – naga Sep 23 '17 at 14:55