Hey - I'm looking for something similar to using vectors and pointers that I've used before in C++; unfortunately, it doesn't seem like there's an equivalent function in VB.net.

What I have is a copy of the array behind a multi-line Rich Text Box, and I need to separate the words from each line (or element of the array) so I can analyze each one separately.

In C++ I would do something like this, so I could continuously expand as needed:

char[] delim = {' '}; //Character that it splits the string at 
                             //(of every occurence)

struct lines {  // Vector
	std::string[] words = Line1.Split(delim); //Array of strings that the 
                                                  //line is split into.
	pointer next; //pointer to the next line, or NULL.

Now, all that said, I don't know if this would actually work in C++, but that's the basic idea behind it:
a vector containing an array of strings, with as many iterations of the vector that I need.

Is there a function in VB.NET that would work in a similar way? I know I've still got arrays and vectors, but using I'm not sure about using vectors in the same way (with pointers).

Any help appreciated.

Recommended Answers

All 6 Replies

you want to get the each item in richtextbox?

If by each item, you mean each word, then yes.
The trick is, I need to keep them separated by line, ergo, array of words in an vector set of the lines.
I've already got a hold of each of the lines - vb.net has an array already that holds the 'string' of each line, and I've just copied that into another one (so that I don't accidentally change the origional), so it's just splitting it that's proving a bother in terms of separate storage.

Just can try some thing like:

Dim sepChars() as Char = {" "c}

For Each strLine In RichTextBox.Lines
 Dim wordInLine As String = strLine.Split(sepChars)
 ...
End For

Hope this helps

That's what I've got at the moment; problem is, I won't know before compiling how many lines I have, so creating the right number of arrays is tricky - this is why I was looking into pointers.
Thanks, though - this did help confirm that I at least got the splitting right.

Maybe you need that:

Dim SplittedLines As New System.Collections.Generic.List(Of String())
Dim sepChars() as Char = {" "c}

For Each strLine In RichTextBox.Lines
 Dim wordsInLine As String() = strLine.Split(sepChars)
 SplittedLines.Add(wordsInLine) 
End For

See the List usage here

Hope this helps

If you use a regular expression it will do a more robust word separation.

Dim rex As New System.Text.RegularExpressions.Regex("\b[a-z|A-Z|']+\b")
Dim s As String = "the Quick, brown's <fox> jumped?"

For Each match As System.Text.RegularExpressions.Match In rex.Matches(s)
    Debug.WriteLine(s.Substring(match.Index, match.Length))
Next

In the above regular expression "\b" matches a word boundary. "[a-z|A_Z|']" matches a word of any case letters and an apostrophe. I'm not sure if my regular expression is the most suitable for what you want but it seems to work. Just replace "s" with your current line and go nuts. For more info see

http://www.regular-expressions.info/reference.html

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.