Question how to double-spin text content in richtextbox ?

jamesvick

Active member
Joined
Jul 19, 2010
Messages
34
Programming Experience
1-3
i want to implement this feature :

if i have a following sentence :

{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}

on a click of button i want to generate this :

my name is james vick and iam a member on this site and iam loving it

or

iam admin and iam a admin on this forum and iam loving it

The basic need is to randomly choose words between {|} braces

I have been able to do this for inner nest i.e. for {member|user|visitor}. But how to include the outer nest of sentences also i.e. {something blah blah {blah1|blah2} and | something else} ?

code for inner nest :

VB.NET:
Private Sub SimpleButton3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles SimpleButton3.Click
        Dim stringWithTextIn As String = RichTextBox1.Text
        Dim regex As New Regex("{(.*?)}")
        Dim r As String = regex.Replace(stringWithTextIn, New MatchEvaluator(AddressOf ReplaceMatch))
        RichTextBox2.Text = r
    End Sub

VB.NET:
Private Function ReplaceMatch(ByVal m As Match) As String
        Dim parts = m.Groups(1).Value.Split("|"c)
        Return parts(r.Next(0, parts.Length))
    End Function

i know i just have to change the regex but what do i add in it to include outer braces?
 
Back
Top