I am a beginner to VB.NET, and I am creating a program that displays a new string in a label. The new string should take a sentence entered by the user and remove every occurrence of a substring supplied by the user. This is my code so far:

    Dim input As String = txtSentence.Text
    Dim remove As String = txtTextRemove.Text
    Dim index As Integer = 0
    Do
        index = input.Remove(0, remove - 1)
    Loop While index > 0
    Me.lblAnswer.Text = index

When I enter " I really dislike that dessert.", and I want to remove "dis". In the label I should get " I really like that dessert." but instead I am getting 0. Why am I getting this? NEED HELP WITH THE CODING!!

Recommended Answers

All 7 Replies

TextToEdit.text.replace("dis", "")

Where would I put it in my code, inside the Do While Loop or outside of it

nowhere, that's the whole code.

Label.text.replace("dis", "")

Dim sentence As String = txtSentence.Text
Dim remove As String = txtTextRemove.Text

    Dim index As Integer = 0


    index = sentence.ToString.Replace("dis", "")
    Me.lblAnswer.Text = index

forget about indexes and integers, try this

sentence = sentence.tostring.replace("dis","")
Me.lblAnswer.Text = sentence

This is what I am suppose to be doing. Look at the attachment.

Thank you for the help I got it!

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.