| Skype: | TextControlSupport | |
| Orders: | 877-462-4772 |

| Author: | TX Text Control Support Department |
| Language: | Visual Basic .NET |
| Version: | 1.0 |
| Released: | August 11, 2004 |
| Last modified: | January 11, 2008 |
| Requirements: | TX Text Control .NET with Visual Studio 2003 |
| Download code: | text2table.zip |

An often requested feature is the 'Text to Table' functionality from MS Word, which converts plain text into a table using delimiters like a comma or a hyphen.
In this sample, we would like to show you how to implement this into your TX Text Control based word processing application.
Consider the user types some words which are seperated with commas in the text. Then the user selects the lines and click on a menu entry to convert them into a table automatically.
We use the Lines Collection of TX Text Control to read the selected text row by row. This string is used in a tokenizer, which splits the string into small pieces based on a delimiter like a comma.
Visual Basic .NET does not includes a tokenizer like in VC++, so we have to write our own. We have placed the class StringTokenizer into the downloadable archive, but not described it here. It returns all tokens in a string, the lines of the TX Text Control.
While (minLine <= maxLine) st = New StringTokenizer(tx.Lines.Item(minLine).Text, delimiter) If (st.CountTokens() > maxItems) Then maxItems = st.CountTokens End If Lines.Add(st.Tokens) minLine = minLine + 1 End While
We fill a Collection with all tokens which will be used to fill the table replacing the selected plain text. This will be done by looping through the whole Lines Collection. We use the Table.Cell Collection to insert the text into the appropriate cells.
For Each line In Lines x = 1 For Each word In line tx.Tables.GetItem(nextTable).Cells.GetItem(y, x).Text = word x = x + 1 Next y = y + 1 Next
Additionally, we have implemented a simple dialog, which allows the user to control the table size and the delimiter. The table size will be calculated automatically based on the counted tokens in the selected text, but the user might want to insert a larger table.
The minimum requirements for this sample application are TX Text Control .NET trial version and Visual Studio .NET 2003.