Replace the words with 'ed' with 'ing'



  • Replace the end of all words with the sentence eding♪ How do you find those words in the line?



  • If, in the words, the last two letters 'ed' should be replaced by 'ing'.

    If you're right in the forehead, you can.

    public string[] ReplaceArrayWords(string[] array, string first, string last){
    List<string> result = new List<string>();
    
    foreach(string word in array){
        if(word.Substring(word.length-first.length,first.length).Equals(first))
            result.Add(word.Substring(0,word.length-first.length)+last);
        else
            result.Add(word);
    }
    

    return result.ToArray();
    }

    c Framework 4.5+ Alexander Petrov)

    public string[] ReplaceArrayWords(string[] array, string first, string last){
    List<string> result = new List<string>();

    foreach(string word in array){
        if(word.EndsWith(first))
            result.Add(word.Substring(0,word.length-first.length)+last);
        else
            result.Add(word);
    }
    

    return result.ToArray();
    }

    later:

    string[] newArray = ReplaceArrayWords(array,"ed","ing");




Suggested Topics

  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2