using System;
namespace MyCompiler {
class Program {
public static void Main(string[] args) {
string str = "This is dotnet interview";
string reverse = reverseStr(str);
//Split words for string into array
string[] words = SplitWords(reverse);
//Final output Method
sortStringWordArray(words);
}
//STEP : 01 => reverse the string
static string reverseStr(string mystr){
string newStr = "";
for(int i=mystr.Length-1;i>=0;i--){
newStr += mystr[i];
}
return newStr;
}
//STEP 02: Convert String into string array.
static string[] SplitWords(string rsrveStr){
return rsrveStr.Split(new char[] { ' ' }, StringSplitOptions.RemoveEmptyEntries);
}
//STEP 03: Sort Array string elements based on length and generate output string.
static void sortStringWordArray(string[] strWords){
for(int i=0;i<strWords.Length-1;i++){
for(int j=0;j<strWords.Length-i-1;j++){
if (strWords[j].Length > strWords[j + 1].Length)
{
string temp = strWords[j];
strWords[j] = strWords[j + 1];
strWords[j + 1] = temp;
}
}
}
Console.WriteLine(string.Join(" ", strWords));
}
}
}
To embed this project on your website, copy the following code and paste it into your website's HTML: