There are many ways to do it, and one of them is using the recursivity; using it, you can define a parser function like
Function Parse(ByVal SourceString As String) As String
'
' Create a temp return info
'
Dim ReturnString As New Text.StringBuilder
'
' The loop position in the source string
'
Dim I As Integer = 0
'
' Sart a new random sequence
'
Randomize()
'
' While there is something in the source
'
Do While I < SourceString.Length
'
' Get the char to process
'
Dim c As Char = SourceString.Chars(I)
'
' Depending on the char
'
Select Case c
Case "{"c
'
' This is an opening so must start a deeper level
'
ReturnString.Append(Parse(SourceString.Substring(I + 1)))
Exit Do
Case "}"c
'
' This is a closing one.
'--------------------------------------------------------
'
' calculate the options using the | separator
'
Dim Options As String() = ReturnString.ToString.Split("|"c)
'
' Clear the return string to get an option.
'
ReturnString = New Text.StringBuilder
'
' Get the option
'
ReturnString.Append(Options(CType(Math.Floor(Rnd() * CType(Options.Length, Single)), Integer)))
'
' Get hte rest of the string past the closing bracket
'
If I < SourceString.Length - 1 Then
'
' Disregard all the source before the ending bracket and reset the pointer
'
SourceString = SourceString.Substring(I + 1)
I = -1
Else
'
' If this is the last char, then nothing more to analyze
'
SourceString = ""
End If
Case Else
'
' this is a normal char
'
ReturnString.Append(c)
End Select
'
' Go for the next char
'
I += 1
Loop
'
' Return the valid string
'
Return ReturnString.ToString
End Function
then you can call the function using
Dim S As String = Parse("{my name is james vick and iam a {member|user|visitor} on this {forum|website|site} and iam loving it | iam admin and iam a {supervisor|admin|moderator} on this {forum|website|site} and iam loving it}")
'
' Then randomly split the parsed text
'
'
' calculate the options using the | separator
'
Dim Options As String() = S.Split("|"c)
'
' And get the final option
'
S = Options(CType(Math.Floor(Rnd() * CType(Options.Length, Single)), Integer))
Hope this helps