Visual Basic: Not using replace or remove, only Length, Substring and Indexof

Tags:
String
VB.NET
Visual Basic
Trying to write a program that replaces and removes certain words WITHOUT Replace or remove methods. Only using functions like: Length, Substring, IndexOf. Example: I type in the input "I love the bikes at Fives Bike Shop." The output would be: "I love the bikes at 5BS." The code is below:
S = txtIn.Text
'Put a space
S = " " & S
output = ""
Acro = ""
Dim L As Integer
L = S.Length
Dim P As Integer
Dim ending, beginning As Integer

For P = 1 To L - 1
    If Acro.Length >= 25 Then
        ending = S.IndexOf("Five Bike Shop", beginning)
        beginning = S.IndexOf("s", beginning) + 1
        Acro = S.Substring(ending)
        output = output & S.Substring(ending) & "5BS"
    End If
Next
txtOut.Text = output
End Sub

End Class
1

Answer Wiki

Thanks. We'll let you know when a new response is added.

Seems like a homework question. I cannot think of a real word case where you would not use the replace. Using replace would save a lot of code. Other than than you would need to scan your input string looking for your data to replace. Capture the starting position of it. Then build a new result and substring the original up to that point, hardcode your replacement text, then add the remaining text from the original string.

Discuss This Question: 1  Reply

 
There was an error processing your information. Please try again later.
Thanks. We'll let you know when a new response is added.
Send me notifications when members answer or reply to this question.
  • carlosdl
    So, what is the question?

    You tell us what you are trying to do, and post some code.  Now what?

    Does it work?  Are you getting errors?  What exactly do you need help with?
    84,745 pointsBadges:
    report

Forgot Password

No problem! Submit your e-mail address below. We'll send you an e-mail containing your password.

Your password has been sent to:

To follow this tag...

There was an error processing your information. Please try again later.

Thanks! We'll email you when relevant content is added and updated.

Following

Share this item with your network: