Drop Down MenusCSS Drop Down MenuPure CSS Dropdown Menu

Thursday 16 March 2017

String based program


String program #8 (Combine two strings)

Enter String1: imagination
Enter String2: hunt
Concatenated string: imaginationhunt

The program for the string is written in C# programming language and will accept two strings as input. The logic is to merge strings. There are two ways to merge strings:
1.    Using in-built function “Concat”
2.    Using ‘+’ operator
 
String based program

Note: If you are new to C# and Console Application. Try to code First C# Program

Note: Read articles on how to use Loops and Conditions.

Let’s find out a simple and easy way to code the program.

Practical Implementation:

using System;

namespace patternProblem.String
{
    class String8     //combine two strings
    {
        static void Main(string[] args)
        {
            Console.Write("Enter String1: ");
            string str1 = Console.ReadLine();
            Console.Write("Enter String2: ");
            string str2 = Console.ReadLine();

            //Method-1: Using in-build function
            Console.WriteLine("Concatenated string: {0}", string.Concat(str1, str2));

            //Method-2: Using '+' operator. '+' is also used to concatenate two strings
            Console.WriteLine("Concatenated string: " + str1 + str2);
           
            Console.ReadKey();
        }
    }
}

Output:
The input string1 here is “Imagination” and string2 is “hunt”. So, based on the input, program will combine those string. The output is shown below:

Enter String1: imagination
Enter String2: hunt
Concatenated string: imaginationhunt
Press any key to continue . . .


For any query, comment us below.

Skip to Main Table String based program

Previous - String based program #6

Next – String based program #8

Click imagination hunt to read latest blogs.


Keep learning and sharing...

No comments:

Post a Comment

Featured post

Think that makes you rich and richer

 Napolean said: “You can think and grow rich, but if you can be brought up like most people with work and you won't starve, this wil...