Thursday, October 1, 2015

stringByReplacingOccurrencesOfString - Replace characters within a string by other characters

Type these codes in the playground:

import UIKit

let str = "Hello##World##123##!!"

var strTemp : String!

strTemp = str.stringByReplacingOccurrencesOfString("##", withString: "\n", options: NSStringCompareOptions.RegularExpressionSearch, range: nil)


println(strTemp)

The result:

Hello
World
123

No comments:

Post a Comment