Private Sub btnCalc_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnCalc.Click
Dim strEnteredString As String = txtInputString.Text.Trim
Dim intEnteredStringChars As Integer = strEnteredString.Length
Dim strGoodSubstring As String = txtInputGoodString.Text.Trim
Dim intGoodSubstringChars As Integer = strGoodSubstring.Length
Dim strBadSubstring As String = txtInputBadString.Text.Trim
Dim intBadSubstringChars As Integer = strBadSubstring.Length
Dim strNewString As String = strEnteredString
Dim strNewStringFinal As String
If strEnteredString.Contains(strBadSubstring) Then
strNewStringFinal = strNewString.Remove(
strNewString = strEnteredString.Insert(intBadSubstringChars, strGoodSubstring)
End If
2 Replies - 616 Views - Last Post: 11 November 2012 - 05:41 PM
#1
Visual Studio, Replacing instances of bad.substring with good.substrin
Posted 11 November 2012 - 02:18 PM
Im using Visual Basic 2010. Im having the user enter a string, good substring, and bad substring (Three text Boxes). I need to have my code find the instances of the bad substring in my string, and replaces each instance with the good substring. I feel like there should be a loop to determine the instances of the bad substring. I just can't wrap my mind around it. Here is all I have so far. Hopefully someone can help me.
Replies To: Visual Studio, Replacing instances of bad.substring with good.substrin
#2
Re: Visual Studio, Replacing instances of bad.substring with good.substrin
Posted 11 November 2012 - 05:23 PM
You do realize that the String class has a Replace() method right?
Unless you are doing it the long way for some reason.
Dim testStr as String = "the brown fox jumped over the lazy dog"
Dim newStr as String = testStr.Replace("the", "a")
' Prints out "a brown fox jumped over a lazy dog"
Console.WriteLine(newStr)
Unless you are doing it the long way for some reason.
This post has been edited by Martyr2: 11 November 2012 - 05:24 PM
#3
Re: Visual Studio, Replacing instances of bad.substring with good.substrin
Posted 11 November 2012 - 05:41 PM
As a matter of fact I am trying to do it the long way haha. I had the if statement but cant figure out how to idwntify remove and replace without using. Replace. Thank you for taking the time to help me toooo :-)
Page 1 of 1
|
|

New Topic/Question
Reply



MultiQuote




|