Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I insert a blank space (" "), when I concatenate a string?

Tags:

java

c#

This question is for C Sharp (and Java maybe :).

When I want to display a message to the console, I want to insert after each "+" a blank space. How can I do this, without inserting manually that blank space?

like image 328
Aaron Avatar asked Dec 24 '10 09:12

Aaron


People also ask

How do I add a space in concatenate Python?

We can also concatenate the strings by using the space ' ' in between the two strings, and the “+” operator is used to concatenate the string with space. To get the output, I have used print(my_str).

How do I concatenate an empty string?

Concatenating with an Empty String Variable You can use the concat() method with an empty string variable to concatenate primitive string values. By declaring a variable called totn_string as an empty string or '', you can invoke the String concat() method to concatenate primitive string values together.


1 Answers

try this

var text = string.Join(" ", new[] {foo, bar, other });
like image 139
Dean Chalk Avatar answered Sep 19 '22 14:09

Dean Chalk