how to add white space between strings

Asked

Viewed 80 times

1

Good,

I have 2 fields: First and Last. in the output the 2 names come out pasted without space between them.

this already thanks for the help.

print

2 answers

1


Just add the space in the string concatenation:

var texto1 = "" + Enter.text!
var texto2 = "" + Enter1.text!
myLabel.text = texto1 =  + " " + texto2
  • OPS! did not work, in practice it only works if when writing the first name gives a space. The output of the two names comes out correctly

  • I changed the answer, test it like I just did there.

  • It didn’t work, The Xcode says: Unary Operator cannot be separated from its operand.

  • myLabel.text = Enter.text! + " " + Enter1.text!

  • By convention Voce should name its variables starting with lower case letter. myLabel.text = enter.text! + " " + enter1.text!

  • It worked, at first it gave an error by not having the text and text1 variables in any other part of the code replaced by underscore and gave _ = " " + Enter.text! _ = " " + Enter1.text! Thanks

Show 1 more comment

0

Another way:

myLabel.text = "\(Enter.text!) \(Enter1.text!)"
  • myLabel.text = text1.text! + " " + text2.text!

Browser other questions tagged

You are not signed in. Login or sign up in order to post.