Hi everyone! I was doing programming and ran into this assignment. It says: create a "textbox1" to let the user enter a sentence. Then create a "textbox2" to let the user enter the text they want to remove. Then create a "textbox3" to let the user enter the word they want to replace.

For example, I enter "I love cookies very much" in "textbox1".
For "textbox2", I enter "cookies".
For "textbox3", I enter "eggs".
The label should then display "I love eggs very much" (the word "cookies" is replaced by the word "egg")

How can I do this? The sentence entered may have different length. So how can I locate the word that the user wants to remove. For this particular sentence, I can use "IndexOf("cookies") to locate the word "cookies". But if the user enter a different sentence, then "IndexOf(...what??...)

That's where i struggle.

And furthermore, how can I locate the "full" word. IndexOf only gives me the # of the first letter in that word. How can i locate where the word ends.

Anyone please help me. Thank you very much for your time.

Recommended Answers

All 6 Replies

Look up the String.Replace(...) function. :)

Thank you. I got it. Sorry for asking such stupid question. Because my teach is so weird, he never teaches us such a thing, and give us an assignment like that. ><

Be thankful for those type of assignments. If you intend to do programming as a job, there will be countless times where a project requirement will have you scurrying for a way to implement it. In fact, I consider any project where I do not have to learn something new or utilize existing knowledge in a new way to be a colossal bore!

By the way, i just run into another problem ><. It says: let the user enter a sentence in a textbox. The second textbox will alow the user to enter what he want to remove from the first textbox.

For example: I enter "I want cookies". Then for the second textbox, I enter "oo". The the label should display "I want ckies" ( "oo" is removed).

I try to use the Replace method.
Me.lblanswer.Text = strenter.Replace(strremove, " ")
I replace the text that the user wants to remove by a "space"

The problem with that is: the label will display "I want c kies" (there are 2 space between the "c" and the "k").
I want it this way "ckies", not "c kies".

So how can I do that?

May you help me, please!

The second parameter can be an empty string. Simply use "" or String.Empty to get your desired result.

Thanks second time. :) I get it now. I just get to study vbn last week, so everything was so strange. i didnt know there is such thing as "". Thank you.

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.