Function to Upper and Lower Case sentences

Bob Sneidar bobs at twft.com
Wed Dec 21 16:46:11 EST 2011


I did something similar recently, where not only was the delimiter important, but preserving the exact delimiter was also important. In my case it was breaking out the parts of a query that might contain AND or OR. What I did was: 

replace " AND " with cr & " AND " & cr in theList
replace " OR " with cr & " OR " & cr in theList

repeat with theLineCount = 1 to the number of lines of theList step 2
  put line theLineCount of theList into theLine
  put line theLineCount +1 into theDelimiter
  -- do some stuff with whatcha got
  put theLine & theDelimiter & cr after theNewList
end repeat

You could modify this to deal with a period and a space, a period and a close parens, a period and a character return or a period and anything else that might apply. Just don't append CR for a single period and cr, or you will end up with blank lines that were not there beforehand. Also, now that I think about it, you should probably also replace "..." with an ellipsis before continuing, and any other thing that might come after a period in normal text. You should end up with a list of sentences, and whatever came after them. Also, now that I think about it some more, you should probably replace 2 cr's with some kind of placeholder  & cr before anything else in a repeat loop to account for multiple CR's. That would throw your function out of sync if an extra line showed up anywhere along the way. 

Bob


On Dec 21, 2011, at 1:02 PM, Sivakatirswami wrote:

> OK yes, Title case is easy... It's sentence case I was looking for because a period/dot is not part of a word. I guess one could use a dot as a line delimiter and then step thru the lines.
> 
> 
> 
> On 12/21/11 10:57 AM, Bob Sneidar wrote:
>> On Dec 21, 2011, at 12:43 PM, Sivakatirswami wrote:
>> 
>>> I have a need to take all caps input  and
>>> 
>>> 1) Lower case all but first letter of sentences
>>> 
>>> 2) Upper case words in a small dictionary I will provide to the function.
>>> 
>>> As anyone cooked up something like this already... if I just had 1) can manage 2)
>>> 
>>> Happy Holidays!
>>> 
>>> Om Shanti
>>> Sivakatirswami
>>> 
>>> Kauai Aadheenam
>>> 
>>> __________________________
>> function titleCase theText, forceIt
>>     if forceIt is true then
>>         put tolower(theText) into theText
>>     end if
>> 
>>     repeat with theWordNum = 1 to the number of words of theText
>>         put toupper(char 1 of word theWordNum of theText)&  \
>>                 char 2 to -1 of word theWordNum of theText \
>>                 into word theWordNum of theText
>>     end repeat
>> 
>>     return theText
>> end titleCase
>> 
>> 
>> _______________________________________________
>> 
> 
> 
> _______________________________________________
> use-livecode mailing list
> use-livecode at lists.runrev.com
> Please visit this url to subscribe, unsubscribe and manage your subscription preferences:
> http://lists.runrev.com/mailman/listinfo/use-livecode





More information about the use-livecode mailing list