w3resource

C# Sharp Exercises: Reverse the words of three or more lengths in a string

C# Sharp String: Exercise-57 with Solution

Write a C# Sharp program that takes a string and reverses the words of three or more lengths in a string. Return the new string. As input characters, only letters and spaces are permitted.

Sample Data:
("The quick brown fox jumps over the lazy dog") -> "ehT kciuq nworb xof spmuj revo eht yzal god"
("Reverse the words of three or more") -> "esreveR eht sdrow of eerht or erom"
("ABcDef") -> "feDcBA"

Sample Solution:

C# Sharp Code:

using System;
using System.Linq;
namespace exercises
{
    class Program
    {
        static void Main(string[] args)
        {

            string text = "The quick brown fox jumps over the lazy dog";
            //string text =" Python";
            //string text = "Red Green Blue White";
            Console.WriteLine("Original strings: " + text);
            Console.WriteLine("\nReverse the words of three or more lengths of the said string:");
            Console.WriteLine(test(text));
        }
        public static string test(string text)
        {
           return string.Join(" ", text.Split(' ').Select(x => x.Length >= 3 ? new string(x.Reverse().ToArray()) : new string(x.ToArray())));
         
        }
    }
}

Sample Output:

Original strings: The quick brown fox jumps over the lazy dog

Reverse the words of three or more lengths of the said string:
ehT kciuq nworb xof spmuj revo eht yzal god

Flowchart :

Flowchart: C# Sharp Exercises - Find the longest common ending between two given strings.

C# Sharp Code Editor:

Improve this sample solution and post your code through Disqus

Previous: Find the longest common ending between two strings.
Next: Check if a string is an anagram of another given string.

What is the difficulty level of this exercise?

Test your Programming skills with w3resource's quiz.



Share this Tutorial / Exercise on : Facebook and Twitter