Hot to sort datatable by length of a column ?

Ontrack16

New member
Joined
Jul 10, 2008
Messages
3
Programming Experience
Beginner
In a datatable I have 2 columns with text.

The data looks like this
"Onderkast", "Base unit"
"Onderkast met 1 deur", "Base unit with 1 door"
"Onderkast met 1 lade", "Base unit with 1 drawer"
...

Now I want to translated a sentence eg
"Onderkast met 1 deur en 2 glazen pottenwagens"

To do that, I would start by sorting the datatable by length of the first column. So it would be :
"Onderkast met 1 deur", "Base unit with 1 door"
"Onderkast met 1 lade", "Base unit with 1 drawer"
"Onderkast", "Base unit"
...

I tried with the command
tblDataTable.Select("Nederlands like 'onderkast%', "Nederlands DESC")

That however doesn't give the right result.
When I try the expression "Length(Nederlands) DESC" then there is -of course- a message that column "Length(Nederlands)" cannot be found.
 
With the sql statement I was able to get the datatable sorted the right way:)

Unfortunately when I run a select on the datatable, it gets out of the right order again:rolleyes:

Even when I don't add the sortorder parameter.

I guess a workaround -like you propose- is needed then.
Too bad because I need to lookup lots of strings and every extra step means extra time.

I guess I will have to tell the users : patience is a virtue :cool:
 
With the sql statement I was able to get the datatable sorted the right way:)

Unfortunately when I run a select on the datatable, it gets out of the right order again:rolleyes:
Of course.. it is nOT the data models job to return or store rows in any order at all. Pray tell why are you using Select() at all?

Too bad because I need to lookup lots of strings and every extra step means extra time.
If you plan on using this as a lookup, please do not use Select. It works by actually creating and compiling a comparator for every time it is run and this step is very, very slow. Please use Find() and set a sensible primary key
 
Solved it as proposed :
- I read in the datatable (dt1, 2 columns : "From" and "To")
- I created a new datatable (dt2, 3 columns : "length(From)", "From", "To")
- I looked up stuff in dt2 by using select("From Like ...", "Length DESC")

I couldn't use find because I don't have unique values.

A word can be replaced by several others in another language.
So I have a datatable with :
WordA -> XWordA
WordA -> XWordB
WordA -> XWordC
...

And it even doesn't go that slow :)
 
Back
Top