I need to concatenate 3 session values Session["First Name"],Session["Middle Name"],Session["Last Name"] with spaces in between.
I tried the following :
Labelname.Text = String.Concat(this.Session["First Name"],"", this.Session["Middle Name"],"", this.Session["Last Name"]);
but I get the result as : firstnamemiddlenamelastname
You are not concatenating spaces, but empty strings.
var empty = ""
var space = " "
So, you need to change your example:
Labelname.Text = String.Concat(this.Session["First Name"]," ", this.Session["Middle Name"]," ", this.Session["Last Name"]);
There are other ways to concatenate strings in C#.
Using the +
operator:
Labelname.Text = this.Session["First Name"] + " " + this.Session["Middle Name"] + " " + this.Session["Last Name"];
Using the C# 6 interpolated strings feature:
Labelname.Text = $"{this.Session["First Name"]} {this.Session["Middle Name"]} {this.Session["Last Name"]}";
Using string.Join
:
Labelname.Text = string.Join(" ", new []{ this.Session["First Name"], this.Session["Middle Name"], this.Session["Last Name"]});
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With