Removal of words on the list



  • Good afternoon! There is a list of different symbols:

    • 84 000888sWord545
    • 324 tipsWordAoshua
    • LostWordFovish

    Should be cut Word and everything after him. The number of symbols before and after a specific word may vary.

    I've read various resources, but only editing has a certain symbol, I'll be very good!



  • Let's set up a method. RemoveWords(str, word)

    In the body of the method, the index is obtained by the method IndexOf(str, word) and Remove(startIndex, length) remove all the symbols.

    Read it. StringBuilder You can. https://docs.microsoft.com/ru-ru/dotnet/api/system.text.stringbuilder?view=net-5.0

    Read it. IndexOf() You can. https://docs.microsoft.com/ru-ru/dotnet/api/system.string.indexof?view=net-5.0

    Read it. Remove() You can. https://docs.microsoft.com/ru-ru/dotnet/api/system.string.remove?view=net-5.0

    static void Main(string[] args)
    {
        string str = "84ыва846ыв88сСлово545выщв";
    
    string removedWordString = RemoveWord(str, "Слово");
    Console.WriteLine(removedWordString);
    Console.ReadKey();
    

    }

    static string RemoveWords(string str, string word)
    {
    StringBuilder builder = new StringBuilder(str);
    int index = str.IndexOf(word);
    builder.Remove(index, str.Length - index);

    return builder.ToString();
    

    }


Log in to reply
 

Suggested Topics

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