For example, this variable needs to add "25" after the "%" character. How can I do it?
var message = "cars %50 discount"
must be "cars %2550 discount"
For example, this variable needs to add "25" after the "%" character. How can I do it?
var message = "cars %50 discount"
must be "cars %2550 discount"
You can do that by replacing '%' with '%25' or whatever characters you'd like to insert after '%':
var message = "cars %50 discount"
message = message.replacingOccurrences(of: "%", with: "%25")
This approach is dangerous, check the this answer for more information and for an alternative approach.
I believe this link provides the answer you need: How can I add Variables into a String?(Swift)
For your example do:
var discountAmount = 2550
var message = "cars %\(discountAmount) discount"
(and the message prints "cars %2550 discount"