loop through a string and create an array?

simpleonline

Active member
Joined
Sep 13, 2011
Messages
33
Programming Experience
Beginner
I have a string where I have created a template so to speak.

VB.NET:
    Dim myvariable as string
    Richtextbox1.text = Richtextbox1.text & "The dog jumped over the" & myvariable & "to find the fox."

I have a list box that contains a list of options that loads into the variable example: fence, bucket, etc.

So the sentences would read like

1. The dog jumped over the fence to find the fox
2. The dog jumped over the bucket to find the fox

Right now I have it coded to display into a rich text box but everything is in the same rich text box.

I'm trying to load the string into an array at the end of each loop this way I can then have each sentence separated.

What would be the best way to do this?

Thanks

:embarassedlaugh:



UPDATE - I guess a better way to look at it would to say rather than sentences it would be text.

VB.NET:
Richtextbox1.text = richtextbox1.text & "this is what I mean by sentence"

How would I tell my app to loop through that rich text box (or I could just use it as a string) and then at the end of the string put the information into an array and then loop back to the beginning and repeat the process until there are no more items to use in the list box?

This way I would have something like this.

The fox jumped over the fence
The fox jumped over the bucket
The fox jumped over the car

Each line of text, or each string would be in a collection that I could do something with like feed it back into another list box.
 
Last edited:
Figured it out. Thanks guys. I actually ended up to just looping through the text and saving each sentence to a text file instead.

Here is the code I used to save each sentence to file.

VB.NET:
            'Set path to textfile:
            Dim myfile As String = "C:\Users\Big Chris\Desktop\TESTER\test" & count & ".txt"
            Dim mystring As String = gold.ToString
            'Create objectwriter:
            Dim objWriter As New System.IO.StreamWriter(myfile)
            'Write string:
            objWriter.Write(mystring)
            'Close objectwriter:
            objWriter.Close()

        Next
 
Back
Top