0

I am gating text This "www%2Egoogle%2Ecom%20%0Await" Then i am using This code for Decrypted let DecodeMSG = msg.stringByReplacingPercentEscapesUsingEncoding(NSUTF8StringEncoding)! Then %20%0A is New line show automaticlly

www.google.com 
wait

how split word from there

i am using this Code

 for var i = 0; i < splitStringArray.count ; i++
            {
                let word:String = splitStringArray[i];

                if word.hasPrefix("www") || word.hasPrefix("http")
                {
                    print(word)
                    let trimmed = word.stringByReplacingOccurrencesOfString("^\\n",
                        withString: "", options: .RegularExpressionSearch)
                    print("trimmed == \(trimmed)")
                    let range: Range<String.Index> = (str.rangeOfString(word)!)
                    let start:Int = Int("\(range.startIndex)")!
                    let end:Int = word.characters.count
                    // print(start)
                    text.addAttribute(TapLabel.LinkContentName, value: word, range: NSMakeRange(start, end))
                    text.addAttribute(NSForegroundColorAttributeName, value: UIColor.blueColor(), range: NSMakeRange(start, end))
                    text.addAttribute(TapLabel.SelectedForegroudColorName, value: UIColor.redColor(), range: NSMakeRange(start, end))






                }

            }


            messageLabel.attributedText = text 

My link create whole word but i want to split word if using new new line

Please help me .

  • 1
    I'm not entirely sure what you want your end result to be, but take a look at the `.componentsSeparatedByString` method for `String` instances. E.g. for your example: `let msg = "www%2Egoogle%2Ecom%20%0Await"`, followed by `let decodedMsg = msg.stringByReplacingPercentEscapesUsingEncoding(NSUTF8StringEncoding)?.componentsSeparatedByString("\n") ?? [""]`, yielding the `String` array with elements separated by new line in original string: `["www.google.com ", "wait"]`. For details, see e.g. [this existing SO thread](http://stackoverflow.com/questions/25678373/swift-split-a-string-into-an-array). – dfrib Feb 25 '16 at 15:22
  • Thankyou i will Try This Solution – Nishant Chandwani Feb 25 '16 at 15:44

0 Answers0