w3resource

C#: Combine two given string of length atleast 1, after removing their first character


C# Sharp Basic Algorithm: Exercise-67 with Solution

Write a C# Sharp program to combine two strings of length at least 1, after removing their first character.

Visual Presentation:

C# Sharp: Basic Algorithm Exercises - Combine two given string of length atleast 1, after removing their first character.

Sample Solution:-

C# Sharp Code:

using System; // Import the System namespace which contains fundamental types and base classes

namespace exercises // Define a namespace called 'exercises'
{
    class Program // Define a class named 'Program'
    {
        static void Main(string[] args) // The entry point of the program
        {
            // Output the result of the test function with different strings as arguments
            Console.WriteLine(test("Hello", "Hi"));    // Test with strings "Hello" and "Hi"
            Console.WriteLine(test("JS", "Python"));   // Test with strings "JS" and "Python"
            Console.ReadLine(); // Wait for user input before closing the console window
        }

        // Function definition of test function that takes two strings 's1' and 's2' and returns a string
        public static string test(string s1, string s2)
        {
            // Concatenate substrings of 's1' and 's2' starting from index 1 (excluding the first character)
            return s1.Substring(1) + s2.Substring(1);
        }
    }
}

Sample Output:

elloi
Sython

Flowchart:

C# Sharp: Flowchart: Combine two given string of length atleast 1, after removing their first character.

C# Sharp Code Editor:

Improve this sample solution and post your code through Disqus

Previous: Write a C# Sharp program to create a new string from two given string one is shorter and another is longer. The format of the new string will be long string + short string + lng string.
Next: Write a C# Sharp program to move the first two characters to the end of a given string of length at least two.

What is the difficulty level of this exercise?

Test your Programming skills with w3resource's quiz.



Follow us on Facebook and Twitter for latest update.