Space between sting and variable



This is probably a stupid question but does any one know how to create a space between a text string and a variable?

(See screen shot for example)


In the above image you can see the message box displaying “The weather inNew YorkIs degrees” however, this should read “The weather in New York Is degrees”.

  • New York - is a variable while - The weather in - is a string of text

Thanks for you help



If you would like to add a space between variable and string just add " ".

So syntax would be: “The weather in " + cityVariable + " is degrees”



Thanks for your response. I still seem to be getting no spaces between text and variable.

Below is my syntax - do you know where I am going wrong?



OK - I think I have it.



Convert the variables to string


Hi @Cormac,
After in give space and give spave before and after is

"The weather in "+city.ToString()+" Is "+tempature.ToString()+" degrees"

Arivu :slight_smile:


a better solution - thanks.


All you need is to have a space before the " within the text

“The weather in[space]”+ city + “[space]Is[space]” + temperature + “[space]degrees”


Use String.Format, that’s exactly what it’s for:
String.Format("The weather in {0} Is {1} degrees", city.ToString(), temperature.ToString())
Depending on your formats, you could specify formats directly in the “placeholders”: