how to multiply a string by the times a variable in Swift tells me

-1

Hello, what happens is that I do not understand how to multiply a string by the number of times a variable tells me and store it in a function, I explain 6 is the number of times it has to be repeated and a! It is the string as I do so that it stays a! a! a! a! a! Do you have to use a loop?

Thanks

    
asked by juan pablo moscoso alvarado 02.06.2018 в 20:35
source

1 answer

0

Actually in Swift you would not need to use any loop just to create the variable as mentioned by the string documentation in swift Something like this:

let cadena = String(repeating: "a!", count: 6)
print(cadena)

Now that if you had a variable for string or number you would only need to replace in the code, for example:

var x: Int = 6
var str: String = "a!"
let cadena = String(repeating: str, count: x)
print(cadena)
    
answered by 02.06.2018 / 21:28
source