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

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.

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

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.