ios - How can I add double quote between double quotes to be a string value? -
i want filter double quotes in text , separate words. when added double quote in double quotes (like """ ), didn't work. tried add way ("\"") in between double quotes didn't work too.
my codes below. can see in findcommonwords function want.
how can solve problem?
thanks.
import uikit import rogoogletranslate import swiftsoup class feeddetailvc: uiviewcontroller, uiwebviewdelegate { @iboutlet weak var txtmain: uitextview! @iboutlet weak var scrollview: uiscrollview! @iboutlet weak var lblheader: uilabel! var commonwordsarray = [string]() var selectedheader = string() override func viewdidload() { super.viewdidload() lblheader.text = selectedheader self.txtmain.sizetofit() dispatchqueue.main.async { self.contentheight = self.lblheader.frame.height + self.txtmain.frame.height self.scrollview.contentsize = cgsize(width: self.view.frame.width, height: self.contentheight + 100) self.reloadinputviews() } findcommonwords() } func findcommonwords() { let textviewtext = txtmain.text var commonwords = textviewtext?.lowercased().components(separatedby: [" ",".",",","=","(",")","-","/",":","\""]).filter({ !$0.isempty }) let rejectedwords: [string] = ["the","on","in","a","an","of","off","up","and","to","are","is","am","—","se","iphone","was","it","at","\""] index in rejectedwords { commonwords = commonwords?.filter{ $0 != index} } let wordcounts = nscountedset(array: commonwords!) let sortedwords = wordcounts.allobjects.sorted(by: {wordcounts.count(for: $0) > wordcounts.count(for: $1) }) [0..<5] ypoint = self.txtmain.frame.height + 15 word in sortedwords { //print("\(word) \(wordcounts.count(for: word)) times") let sortedwordslabel = uilabel() sortedwordslabel.frame = cgrect(x: 0, y: 0, width: 120, height: 25) sortedwordslabel.center = cgpoint(x: 80, y: ypoint) sortedwordslabel.text = word as? string sortedwordslabel.font = uifont(name: "helveticaneue-bold", size: 15) sortedwordslabel.textalignment = .left self.scrollview.addsubview(sortedwordslabel) ypoint += 25 commonwordsarray.append(word as! string) } } }
“string literals can include following special characters:
the escaped special characters
\0
(null character),\\
(backslash),\t
(horizontal tab),\n
(line feed),\r
(carriage return),\"
(double quote) ,\'
(single quote)”
excerpt from: apple inc. “the swift programming language (swift 2.1).” ibooks. https://itunes.apple.com/ca/book/the-swift-programming-language-swift-3-1/id881256329?mt=11
Comments
Post a Comment