w3resource
C# Sharp Programming Exercises

C# Sharp Exercises: Check if a given string contains 'w' character between 1 and 3 times

C# Sharp Basic: Exercise-41 with Solution

Write a C# program to check if a given string contains 'w' character between 1 and 3 times.

Pictorial Presentation:

C# Sharp Exercises: Check if a given string contains 'w' character  between 1 and 3 times

Sample Solution:

C# Sharp Code:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
public class Exercise41
{
    public static void Main( )
    {
        Console.Write("Input a string (conatins at least one 'w' char) : ");
        string str = Console.ReadLine();
        var count = str.Count(s => s == 'w');
        Console.WriteLine("Test the string contains 'w' character  between 1 and 3 times: ");
        Console.WriteLine(count>=1 && count <= 3);   
    }
}

Sample Output:

Input a string (conatins at least one 'w' char) : w3resource           
Test the string contains 'w' character  between 1 and 3 times:         
True 

Flowchart:

Flowchart: C# Sharp Exercises - Check if a given string contains 'w' character  between 1 and 3 times

C# Sharp Code Editor:

Improve this sample solution and post your code through Disqus

Previous: Write a C# program to check the nearest value of 20 of two given integers and return 0 if two numbers are same.
Next: 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.

What is the difficulty level of this exercise?



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