Removing first occurrence of string within a string?
Hi everyone
I'm wondering how i could remove the first occurrence of a set of characters from a string, and then looping until there are no characters left in the string.
For example:
I want to remove the first "wer" from "qwertyqwertyqwerty", so that the string then reads "qtyqwertyqwerty".
Any ideas on how to do that?
EDIT: Clarified example.
Re: Removing first occurrence of string within a string?
string.replace()
Code:
Dim str As String = "qwerty"
Console.WriteLine(str.Replace("wer", ""))
Console.ReadLine()
generally when you have a question about string manipulation the first place to look is msdn.
Re: Removing first occurrence of string within a string?
vb.net Code:
Dim testString As String = "Chumbawumba"
MsgBox(Replace(testString, "umb", "", 1, 1)) 'source, search string, replacement, start, number of repetitions
Re: Removing first occurrence of string within a string?
Sorry, I meant if the substring you want to remove occurs more than once in a string. Like removing the first "wer" from "qwertyqwertyqwerty".
Re: Removing first occurrence of string within a string?
Quote:
Originally Posted by
h33t
Sorry, I meant if the substring you want to remove occurs more than once in a string. Like removing the first "wer" from "qwertyqwertyqwerty".
Yes, I know. That's what my code does. If you'd tried it you would know that it changes Chumbawumba to Chawumba.