w3resource
C# Sharp Programming Exercises

C# Sharp Exercises: Create a new string where the first 4 characters will be in lower case

C# Sharp Basic: Exercise-42 with Solution

Write a C# program to create a new string where the first 4 characters will be in lower case. If the string is less than 4 characters then make the whole string in upper case.

Pictorial Presentation:

>C# Sharp Exercises: Create a new string where the first 4 characters will be in lower case

Sample Solution:

C# Sharp Code:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
public class Exercise42
{
    public static void Main( )
    {
        Console.Write("Input a string: ");
        string str = Console.ReadLine();
         if (str.Length < 4) 
           Console.WriteLine(str.ToUpper());
         else
           Console.WriteLine(str.Substring(0, 4).ToLower() + str.Substring(4, str.Length -4));
    }
}

Sample Output:

Input a string: w3r                                                    
W3R

Flowchart:

Flowchart: C# Sharp Exercises - Create a new string where the first 4 characters will be in lower case

C# Sharp Code Editor:

Improve this sample solution and post your code through Disqus

Previous: Write a C# program to check if a given string contains 'w' character between 1 and 3 times.
Next: Write a C# program to check if a given string starts with "w" and immediately followed by two "ww".

What is the difficulty level of this exercise?



New Content: Composer: Dependency manager for PHP, R Programming