C#C
C#3y ago
احمد

❔ ✅ A word with the length of > 5 will be reversed, e.g. hello -> olleh

Write a function that takes in a string of one or more words, and returns the same string, but with all five or more letter words reversed (Just like the name of this Kata). Strings passed in will consist of only letters and spaces. Spaces will be included only when more than one word is present.

Examples:

spinWords( "Hey fellow warriors" ) => returns "Hey wollef sroirraw" 
spinWords( "This is a test") => returns "This is a test" 
spinWords( "This is another test" )=> returns "This is rehtona test"


my code:

using System.Collections.Generic;
using System.Linq;
using System;
using System.Text;



public class Kata
{
  public static string SpinWords(string sentence)
  {
    string[] words = sentence.Split(" ");
    foreach (string word in words){
      if (word.Length() >= 5){
      StringBuilder sb = new StringBuilder(word);
      words[word] = sb.Reverse();
        }
      string connected_string = words.join(' ');
      return connected_string;

    }
    
    string sen = SpinWords("this is a trial sentence.");
    Console.WriteLine(sen);
    
  }
}


error :

src/Solution.cs(14,16): error CS1955: Non-invocable member 'string.Length' cannot be used like a method.
src/Solution.cs(16,13): error CS0029: Cannot implicitly convert type 'string' to 'int'
src/Solution.cs(16,24): error CS1061: 'StringBuilder' does not contain a definition for 'Reverse' and no accessible extension method 'Reverse' accepting a first argument of type 'StringBuilder' could be found (are you missing a using directive or an assembly reference?)
src/Solution.cs(18,39): error CS1061: 'string[]' does not contain a definition for 'join' and no accessible extension method 'join' accepting a first argument of type 'string[]' could be found (are you missing a using directive or an assembly reference?)
src/Solution.cs(10,24): error CS0161: 'Kata.SpinWords(string)': not all code paths return a value
Was this page helpful?