aotian16
aotian16

Reputation: 819

how to use separator param of print in swift2

Sorry for newbee question.

I really do not know how to use separator param in print

var str = "Hello, playground"
var strs = ["abc","def"]

print(str)
print(strs, separator: ",", terminator: "")
print(str, separator: ",", terminator: "\n")

Upvotes: 2

Views: 1192

Answers (2)

Swifty Python
Swifty Python

Reputation: 11

print ("rob" ,"mark" , "hanna" , separator:"$") // prints rob$mark$hanna

To use separator we need to pass multiple string inside print function.

Upvotes: 0

jtbandes
jtbandes

Reputation: 118691

print accepts its arguments separately, so you can do this:

print("abc", "def", separator: ",")

But you have an array of strings, so you should do this:

print(strs.joinWithSeparator(","))

Upvotes: 4

Related Questions