I have this :
var attributedString = NSMutableAttributedString(string:"Welcome %@ to %@")
And I want to format this to add some other NSMutableAttributedString instead of %@
How can I achieve that?
Thanks
You can replace NSAttributeString with another NSAttributeString by following way. here in this example, you need to fine location of %@ symbol.
let stringVariable = "Welcome @ location"
var attributedString = NSMutableAttributedString(string:stringVariable)
var attributedStringAnother = NSMutableAttributedString(string:"abc")
attributedString.replaceCharactersInRange(NSRange(location: 8,length: 1), withAttributedString: attributedStringAnother)
println(attributedString)
Here location: 8 is a location @ symbol.
Output is :
Welcome abc location{
}
Hope this help you.
Try this:
var attributedString = NSMutableAttributedString(string:"Welcome %@ to %@")
let result = attributedString.string.stringByReplacingOccurrencesOfString("%@", withString:"TEST")
var newAtrString = NSMutableAttributedString(string: result)