954,557 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

Multidimensional Arrays / Vectors and Pointers

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.

debuggger
Newbie Poster
7 posts since May 2009
Reputation Points: 10
Solved Threads: 0
 

you want to get the each item in richtextbox?

Pgmer
Master Poster
714 posts since Apr 2008
Reputation Points: 54
Solved Threads: 121
 

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.

debuggger
Newbie Poster
7 posts since May 2009
Reputation Points: 10
Solved Threads: 0
 

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

lolafuertes
Master Poster
798 posts since Oct 2008
Reputation Points: 120
Solved Threads: 167
 

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.

debuggger
Newbie Poster
7 posts since May 2009
Reputation Points: 10
Solved Threads: 0
 

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

lolafuertes
Master Poster
798 posts since Oct 2008
Reputation Points: 120
Solved Threads: 167
 

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

Reverend Jim
Posting Shark
Moderator
1,169 posts since Aug 2010
Reputation Points: 253
Solved Threads: 159
 

This article has been dead for over three months

Post: Markdown Syntax: Formatting Help
You
View similar articles that have also been tagged: