-4

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"

2

2 Answers 2

0

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.

Sign up to request clarification or add additional context in comments.

Comments

-1

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"

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.