Hi Jordi,
I know this isn't as straightforward as Regex.Split(), but it does exactly
what you want.
Begin code:
===================================
imports Microsoft.VisualBasic
imports System
imports system.Text.RegularExpressions
imports System.Collections
public module MyModule
Sub Main()
Dim myItems as New ArrayList
myItems = getValues("*One#*Two#*Three#")
For each item as string in myItems
Console.WriteLine( item & VbCrLf)
next
Console.ReadLine()
end sub
'Here is where the real work gets done
Function getValues(ByVal Input As String) As ArrayList
Dim RegexObj As String = "\*(?<ValueIwant>.+?)\#"
Dim options As RegexOptions = RegexOptions.None
Dim matches As MatchCollection = Regex.Matches(Input, RegexObj,
options)
Dim myMatchArray As New ArrayList
For Each foundItem As Match In matches
myMatchArray.Add(foundItem.Groups("ValueIwant").Va lue)
Next
'You could skip the above loop and access
'found items directly. For example:
'matches.Item(i).Groups("ValueIwant").Value
'Where i is an integer >= 0
Return myMatchArray
End Function
end module
===================================
End Code.
I don't think that using the Split function is the way to go here because
you have two possible characters to match. You could use an expression like:
(\*\#|\*) but I don't know if that would confuse the Split function. You can
try.
I hope this helped.
Chris
"Jordi Rico" <jordirico@gmail.comwrote in message
news:1161005330.270951.227920@i42g2000cwa.googlegr oups.com...
Quote:
Hi,
>
I know I can split a string into an array doing this:
>
Dim s As String()=Regex.Split("One-Two-Three","-")
>
So I would have:
>
s(0)="One"
s(1)="Two"
s(2)="Three"
>
The problem is, I am receiving some kind of data this way:
>
"*One#*Two#*Three#", it is, every word starts with "*" and ends with
"#"...
>
Is there any way of using Regex to split it like the previous example??
>
Thanks in advance
>