Combine String Variables in C# with different Symbols

 

Whenever you want to combine strings with some special characters, C# provides different ways to combine the strings for different symbols.

 

If you just want to add different string variables just use plus(+) operator to combine the strings as shown below.

 

            string str1 = "This is One String ";

            string str2 = "This is Second String ";

 

            string str3 = str1 + str2;//str3 is result string

 

To Add the Tab character between strings use \t  symbol while combining the strings as shown below.

          

            string str1 = "This is One String \t";

            string str2 = "This is Second String ";

 

            string str3 = str1 + str2;//str3 is result string with tab character in between

 

To Add newline between strings use \n symbol between strings as shown below.

 

            string str1 = "This is One String \n";

            string str2 = "This is Second String ";

 

            string str3 = str1 + str2;//str3 is result string with new character in between

 

To display the backslash in string use \\ symbol while adding two strings as shown below.

 

            string str1 = "This is One String \\";

            string str2 = "This is Second String ";

 

            string str3 = str1 + str2;//str3 is result string with backslash character in between

 

To display the quotation in string use \" symbol in string as shown below.

 

            string str1 = "This is One \"quoation\"";

            string str2 = "This is Second String ";

 

            string str3 = str1 + str2;//str3 is result string with quoation character in between