home *** CD-ROM | disk | FTP | other *** search
- *****************************************************************
- FUNCTION CAPFIRST (string)
- *****************************************************************
-
- * Capitalize the first letter of each word in a string
-
- * Copyright(c) 1991 -- James Occhiogrosso
-
-
-
- LOCAL position := 0, punct_mark := '.,-"', ;
- ret_string := temp_word := word := ''
-
- DO WHILE LEN(string) > 0
-
- * Extract a word from the passed string
- word = PARSE(@string)
-
- * Capitalize first letter of word
- word = UPPER(SUBSTR(word,1,1)) + LOWER(SUBSTR(word,2))
-
- * Test for period, comma, dash or double quotation mark
- FOR counter = 1 TO 4
- temp_word = ''
-
- * If any exist, get position in word
- position = AT(SUBSTR(punct_mark, counter, 1), word)
-
- DO WHILE position > 0
-
- * Capitalize first letter after punctuation mark
- temp_word = temp_word + SUBSTR(word, 1, position) +;
- UPPER(SUBSTR(word, position + 1, 1))
-
- * And trim original word
- word = SUBSTR(word, position + 2)
-
- * Are there any more of the same mark in string?
- position = AT(SUBSTR(punct_mark, counter, 1), word)
-
- IF position = 0
- * If not, we are done. Otherwise, loop
- word = temp_word + word
- EXIT
- ENDIF
-
- ENDDO
- NEXT
-
- * Test for an apostrophe
- position = AT("'", word)
-
- IF position > 0
-
- * If one exists capitalize first letter after it if
- * it follows a capitol letter. (Names like "O'Brian")
-
- IF ISUPPER(SUBSTR(word, position-1))
- word = SUBSTR(word, 1, position) + ;
- UPPER(SUBSTR(word, position + 1, 1)) + ;
- SUBSTR(word, position + 2)
- ENDIF
- ENDIF
-
- * Add word to return string
- ret_string = ret_string + word + ' '
-
- ENDDO
-
- * Set local string equal to return string
- string = ret_string
-
- RETURN ret_string
-
-