0

hi ,

i am trying to write code to remove specific word from the text entered by the user
do

 do
            {
                Console.WriteLine("enter your text");
                input = Console.ReadLine();
                text = input.ToLower();


                    result = text.Replace("remove", "");
                Console.WriteLine("Edited text:" +result);


            } while(text == null);            {


            Console.WriteLine("enter your text");
            input = Console.ReadLine();
            text = input.ToLower();


                result = text.Replace("remove", "");
            Console.WriteLine("Edited text:" +result);


        } while(text == null);
        in the above code i tried to remove the word remove from the text entered by the user.
        but if i type removed instead of remove it should not replace it however my program is               replacing it. any idea how to proceed further
        for example if my input is: remove the word remove (this case output is correct)
                            output:the word  
        where as if i type input:removed the word remove
                           output:d the word (which is wrong)
        thanks in advance
3
Contributors
2
Replies
25
Views
3 Years
Discussion Span
Last Post by Fenrir()
1

I can't replicate your issue.

Works fine with:

            Console.Write("Enter your text: ");
            string Input = Console.ReadLine();
            Input = Input.ToLower();
            string Result = Input.Replace("remove", "");
            Console.WriteLine("Edited text: " + Result);
            Console.ReadLine();

Sentence: "There is one word to remove in this sentence"

Tested with "remove" and "removed", remove worked, removed didn't.

0

Sorry if this reply is a bit late but i was curious. I replicated the problem as you are only replacing a partial match. Check this out for a simple and effective solution Click Here

Edited by Fenrir()

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.