Mailing List Archive: 49091 messages
  • Home
  • Script library
  • AltME Archive
  • Mailing list
  • Articles Index
  • Site search
 

Custom Capitalize Function

 [1/3] from: louisaturk::eudoramail::com at: 24-May-2002 15:31


Hi rebols, I need a function to capitalize the first character after the second space in string-b only if the first character after the second space in string a is capitalized. Example: string-a: "Chapter 1:1 Itu besar merah rumah." string-b: "Chapter 1:1 the big red house." capitalize-it string-a string-b string-b: "Chapter 1:1 The big Red house." This function is used right in the heart of a script that processes a rather massive document, so speed is essential. Any ideas for a fast, elegant function? Louis

 [2/3] from: carl:cybercraft at: 25-May-2002 11:13


On 25-May-02, Dr. Louis A. Turk wrote:
> Hi rebols, > I need a function to capitalize the first character after the second
<<quoted lines omitted: 7>>
> a rather massive document, so speed is essential. > Any ideas for a fast, elegant function?
Hi Louis, Try... capitalize-it: function [a [string!] b [string!]][found][ if not found: find/tail find/tail a " " " " [return] if all [found/1 >= #"A" found/1 <= #"Z"] [ if not found: find/tail find/tail b " " " " [return] if all [found/1 >= #"a" found/1 <= #"z"] [ change found to-char to-integer found/1 - 32 ] ] ] Seems to work...
>> a: "a b c" b: "x y z" capitalize-it a b
== none
>> a
== "a b c"
>> b
== "x y z"
>> a: "a b C" b: "x y z" capitalize-it a b
== ""
>> a
== "a b C"
>> b
== "x y Z" If you're sure all your strings will have two spaces in you could take out the checks for that. ie, remove the "if not" and "[return]" from the two lines where the strings are searched. There's probably a faster way, but this shouldn't be too slow - hopefully. (: -- Carl Read

 [3/3] from: louisaturk:eudoramail at: 24-May-2002 20:50


At 11:13 AM 5/25/2002 +1200, you wrote:
>Try... >capitalize-it: function [a [string!] b [string!]][found][
<<quoted lines omitted: 22>>
>out the checks for that. ie, remove the "if not" and "[return]" from >the two lines where the strings are searched.
So far it works great! I'll be testing it extensively over the next few weeks. No news will mean it works and no bugs. Many thanks. Your code complete a script that is very important to me. Louis

Notes
  • Quoted lines have been omitted from some messages.
    View the message alone to see the lines that have been omitted