|
-
Oct 23rd, 2012, 02:45 PM
#1
Thread Starter
New Member
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.
Last edited by h33t; Oct 23rd, 2012 at 03:35 PM.
-
Oct 23rd, 2012, 02:56 PM
#2
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.
-
Oct 23rd, 2012, 03:06 PM
#3
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
As the 6-dimensional mathematics professor said to the brain surgeon, "It ain't Rocket Science!"
Reviews: "dunfiddlin likes his DataTables" - jmcilhinney
Please be aware that whilst I will read private messages (one day!) I am unlikely to reply to anything that does not contain offers of cash, fame or marriage!
-
Oct 23rd, 2012, 03:31 PM
#4
Thread Starter
New Member
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".
-
Oct 23rd, 2012, 03:54 PM
#5
Re: Removing first occurrence of string within a string?
 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.
As the 6-dimensional mathematics professor said to the brain surgeon, "It ain't Rocket Science!"
Reviews: "dunfiddlin likes his DataTables" - jmcilhinney
Please be aware that whilst I will read private messages (one day!) I am unlikely to reply to anything that does not contain offers of cash, fame or marriage!
Tags for this Thread
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|