Sorting text

Marielle Lange mlange at widged.com
Wed Mar 7 06:32:11 EST 2007


Hi Greg,

> 1. Does anyone have a similar program

If you download SoSmartSoftware excellent revonline picker:
<http://www.sosmartsoftware.com/?r=revolution&l=en>
You can look for "user movable fields" or look for "Troutfoot" on  
revonline.

> My plan was to shuffle a sentence and get him to click on words to  
> paste the word into another text box in the correct order.

Feel free to contact me on list or privately if you need any help on  
this (send me a copy if you post on list as I don't always have the  
time to check out each post on the list).

That's an exercise I need to add to my exercist collection:
<http://projects.widged.com/exercist/drupal/?q=node/610>

To get a better idea of what you are after, in the collection at:   
<http://projects.widged.com/exercist/gallery/>
What is the closest to what you have in mind:  (1) Unscrambel (2)  
Unscramble the sentence  (3) Sentence Reconstruction (4) Mixed-up  
Sentence (5) Fridge Magnets... or something different?


> 2. Sorting. I am using the "sort" command to sort the words in a  
> container from the text field, but they are not sorting. If I  use  
> a few lines of text, then these get sorted, but I was under the  
> impression that if the line "sort items of holder" (holder as a  
> variable) is used, then the words in a container would be sorted.  
> But it is not.

<code>
on mouseup
   put the text of field 1 into tText
   put replacetext(tText, "[^\w\s]", "") into tText
   put replacetext(tText, "\b\d+\b", "") into tText
   put replacetext(tText, "\s+", " ") into tText
   set the itemdel to " "
   sort items of tText by word 1 of each
   put tText
   put cr & "---" & cr & deleteDuplicates(tText, true) after message
   put cr & "---" & cr & deleteDuplicates(tText, false) after message
end mouseup

function deleteDuplicates pText, pCaseSensitive
   if pText is empty then return empty
   ----
   if pCaseSensitive is true then
     set the casesensitive to true
   else
     -- set the casesensitive to false
     put tolower(pText) into pText
   end if
   ----
   set the itemdel to " "
   repeat with x = the number of items in pText down to 2
       if item x of pText = item (x-1) of pText then delete item x of  
pText
   end repeat
   return pText
end deleteDuplicates

</code>

The first replacetext will get rid of stuff like "?.:," (\w = word  
character, \s = spacing character; [^xy] = any character but x or y).  
You may want it or not, up to you to see. The second one will get rid  
of any number or sequence of digits on their own (\b = word boundary,  
\d = digit). The third one will replace any sequence of spaces, tabs  
or any other spacing characters with a single space.

You may have or not some use of the second function, to delete  
duplicates within the sorted text (useful to avoid mutiple instances  
of "the", "in", etc.)

Best,
Marielle

------------------------------------------------
Marielle Lange (PhD),  http://widged.com
Bite-size Applications for Education





More information about the use-livecode mailing list