Space between sting and variable


#1

Hello,

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)

image

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


#2

Hi,

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

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


#3

Hi,

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?

image


#4

OK - I think I have it.

image


#5

@Cormac
Convert the variables to string
Regards,
Mahesh


#6

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

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

Regards,
Arivu :slight_smile:


#7

a better solution - thanks.


#8

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

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


#9

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”:
https://www.dotnetperls.com/format-vbnet