Hi Peter,
Is there a special reason that you take the answers from 2 MVP's as the
right answer and tell with that explictly that mine is wrong.
The split for this is come in this newsgroup from a joke from me, because I
saw everybody was giving an answer on a very simple question and I thought I
can make even another one. It works, but it is very slow when the string
become longer. (What I did prove later in the same thread)
I did give the advice to take the replace.
Try this
\\\
Dim oldstring As String = "**item1%%**item2%%**item3%%"
Dim newstring As String = Replace(oldstring, "**", " ")
newstring = Replace(newstring, "%%", "")
' or if you like this
Dim alternativesting As String = oldstring.Replace("**", " ").Replace("%%",
"")
///
And than test them all on the performance, I am quiet sure that the first
method although it goes twice times through it, will be the fastest.
(I have done tests with all the methods that are now described)
Cor
If you just need to return the substrings delimited by "%%", the split is
a quick through.
Also the regex will give you more flexible function, but you need to know
the pattern first.
Here goes the codes
Dim myString As String = "**item1%%**item2%%**item3%%"
'return **item1,**item2,**item3, use split method
Dim myArray() As String = Split(myString, "%%", ,
CompareMethod.Text)
'use the regex method will be more flexible.
Dim r As Regex = New Regex("(item[0-9])%%",
RegexOptions.IgnoreCase) Dim mc As MatchCollection = r.Matches(myString)
For i As Integer = 0 To mc.Count - 1
'writeout item1,item2,item3,
Console.WriteLine(mc(i).Groups(1).ToString)
Next
Best regards,
Peter Huang
Microsoft Online Partner Support
Get Secure! - www.microsoft.com/security
This posting is provided "AS IS" with no warranties, and confers no
rights.