Skip to main content
added 56 characters in body
Source Link
Sunkas
  • 9.7k
  • 9
  • 67
  • 103

A category that modifies an existing mutable String:

extension String { mutating func replace(originalString:String, withString newString:String)  {   let replacedString = self.stringByReplacingOccurrencesOfString(originalString, withString: newString, options: nil, range: nil)   self = replacedString } } 

Use:

name.replace(" ", withString: "+") 

A category that modifies an existing mutable String:

mutating func replace(originalString:String, withString newString:String) { let replacedString = self.stringByReplacingOccurrencesOfString(originalString, withString: newString, options: nil, range: nil) self = replacedString } 

Use:

name.replace(" ", withString: "+") 

A category that modifies an existing mutable String:

extension String { mutating func replace(originalString:String, withString newString:String)  {   let replacedString = self.stringByReplacingOccurrencesOfString(originalString, withString: newString, options: nil, range: nil)   self = replacedString } } 

Use:

name.replace(" ", withString: "+") 
Source Link
Sunkas
  • 9.7k
  • 9
  • 67
  • 103

A category that modifies an existing mutable String:

mutating func replace(originalString:String, withString newString:String) { let replacedString = self.stringByReplacingOccurrencesOfString(originalString, withString: newString, options: nil, range: nil) self = replacedString } 

Use:

name.replace(" ", withString: "+")