home *** CD-ROM | disk | FTP | other *** search
/ Shareware Overload / ShartewareOverload.cdr / database / mixcaps.zip / MIXCAPS.DB3
Text File  |  1988-02-01  |  3KB  |  99 lines

  1. Converting to Initial Caps
  2.  
  3. It is common practice to enter data into computers in all capital
  4. letters. It is faster and you don't need to worry about the state
  5. of the CapsLock toggle. One day, though, you'll want to transfer
  6. data from a dBASE III PLUS database file to a word processor to
  7. generate meged form letters,Then it would be nice to have the
  8. names and addresses with initial caps, as they would appear on a
  9. letter.
  10.  
  11. Icaps.PRG is a program that converts a string to initial caps. It
  12. extracts each space-delimited word from the string, uppercases
  13. the first letter, and lowercases the rest. Icaps looks for common
  14. places where a letter in the middle of a word should be
  15. capitalized.
  16.  
  17. If a word begins with "MC," the "C" is lowercase, and the letter
  18. following the "C" is capitalized, as in Old McDonald.
  19.  
  20. When an apostrophe occurs within the first three letters of a
  21. word, the letter following the apostrophe is capitalized, as in
  22. O'Rourke.
  23.  
  24. Letters following hyphens, periods, or ampersands occurring
  25. anywhere within a word are capitalized. Icaps is called with the
  26. syntax
  27.  
  28. DO Icaps with <memvar>
  29.  
  30. A short program that calls Icaps can convert an entire database
  31. to initial caps.
  32.  
  33. USE <database>
  34. DO While .NOT> EOF()
  35.      temp = <field to convert>
  36.      DO Icaps WITH temp
  37.      REPLACE <field to convert> WITH temp
  38.      SKIP
  39. ENDDO
  40.  
  41. Icaps.PRG will take a bulk of the conversion. However, a manual
  42. inspection of the results will be required to deal with other
  43. exceptions.
  44.  
  45. Icaps.PRG
  46. * Program ...: Icaps.PRG
  47. * Author ....: James Chuang
  48. * Date ......: December 1, 1987
  49. * Versions ..: dBASE III PLUS, 1.0 and 1.1
  50. * Notes .....: Uppercases the first letter of each word in a 
  51. *              memory variable.
  52. *
  53. *              Usage:  DO Icaps WITH <memvar>
  54. *
  55. PARAMETERS string
  56. *
  57. oldstr = LTRIM(TRIM(string)) + " "
  58. string = ""
  59. DO WHILE LEN(oldstr) > 0
  60.     tempstr = UPPER(LEFT(oldstr, AT(" ", oldstr)))
  61.     oldstr + LTRIM(STUFF(oldstr, 1, LEN(tempstr), ""))
  62.     IF .NOT. ("&" $ tempstr .OR. ['] $ tempstr .OR.;
  63.                             "." $ tempstr .OR. "-" $ tempstr)
  64.         tempstr = UPPER(LEFT(tempstr, 1)) + LOWER(SUBSTR(tempstr, 2))
  65.     ELSE
  66.         counter  = 1
  67.         capnext  = .T.
  68.         tempstr2 = ""
  69.         DO WHILE counter <= LEN(tempstr)
  70.             pchar + SUBSTR(tempstr, counter, 1)
  71.             DO CASE
  72.             CASE capnext
  73.                 tempstr2 = tempstr2 + UPPER(pchar)
  74.                 capnext  = .F.
  75.             CASE AT(pchar, ".-") > 0
  76.                 capnext = .T.
  77.                 tempstr2 = tempstr2 + pchar
  78.             CASE pchar = [']
  79.                 capnext = IIF((LEN(tempstr) - counter > 3), .T., .F.)
  80.                 tempstr2 = tempstr2 + "'"
  81.             CASE pchar = "&"
  82.                 tempstr2 = UPPER(tempstr)
  83.                 EXIT
  84.             OTHERWISE
  85.                 tempstr2 = tempstr2 + LOWER(pchar)
  86.             ENDCASE
  87.             counter = counter + 1
  88.         ENDDO
  89.         tempstr = tempstr2
  90.     ENDIF
  91.     IF AT("Mc", tempstr) = 1 .AND. LEN(TRIM(tempstr)) > 2
  92.         tempstr = "Mc" + UPPER(SUBSTR(tempstr, 3, 1)) + SUBSTR(tempstr, 4)
  93.     ENDIF
  94.     string = string + tempstr
  95. ENDDO
  96. string = TRIM(string)
  97. RETURN
  98. * EOP Icaps.PRG
  99.