home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Shareware Overload
/
ShartewareOverload.cdr
/
database
/
mixcaps.zip
/
MIXCAPS.DB3
Wrap
Text File
|
1988-02-01
|
3KB
|
99 lines
Converting to Initial Caps
It is common practice to enter data into computers in all capital
letters. It is faster and you don't need to worry about the state
of the CapsLock toggle. One day, though, you'll want to transfer
data from a dBASE III PLUS database file to a word processor to
generate meged form letters,Then it would be nice to have the
names and addresses with initial caps, as they would appear on a
letter.
Icaps.PRG is a program that converts a string to initial caps. It
extracts each space-delimited word from the string, uppercases
the first letter, and lowercases the rest. Icaps looks for common
places where a letter in the middle of a word should be
capitalized.
If a word begins with "MC," the "C" is lowercase, and the letter
following the "C" is capitalized, as in Old McDonald.
When an apostrophe occurs within the first three letters of a
word, the letter following the apostrophe is capitalized, as in
O'Rourke.
Letters following hyphens, periods, or ampersands occurring
anywhere within a word are capitalized. Icaps is called with the
syntax
DO Icaps with <memvar>
A short program that calls Icaps can convert an entire database
to initial caps.
USE <database>
DO While .NOT> EOF()
temp = <field to convert>
DO Icaps WITH temp
REPLACE <field to convert> WITH temp
SKIP
ENDDO
Icaps.PRG will take a bulk of the conversion. However, a manual
inspection of the results will be required to deal with other
exceptions.
Icaps.PRG
* Program ...: Icaps.PRG
* Author ....: James Chuang
* Date ......: December 1, 1987
* Versions ..: dBASE III PLUS, 1.0 and 1.1
* Notes .....: Uppercases the first letter of each word in a
* memory variable.
*
* Usage: DO Icaps WITH <memvar>
*
PARAMETERS string
*
oldstr = LTRIM(TRIM(string)) + " "
string = ""
DO WHILE LEN(oldstr) > 0
tempstr = UPPER(LEFT(oldstr, AT(" ", oldstr)))
oldstr + LTRIM(STUFF(oldstr, 1, LEN(tempstr), ""))
IF .NOT. ("&" $ tempstr .OR. ['] $ tempstr .OR.;
"." $ tempstr .OR. "-" $ tempstr)
tempstr = UPPER(LEFT(tempstr, 1)) + LOWER(SUBSTR(tempstr, 2))
ELSE
counter = 1
capnext = .T.
tempstr2 = ""
DO WHILE counter <= LEN(tempstr)
pchar + SUBSTR(tempstr, counter, 1)
DO CASE
CASE capnext
tempstr2 = tempstr2 + UPPER(pchar)
capnext = .F.
CASE AT(pchar, ".-") > 0
capnext = .T.
tempstr2 = tempstr2 + pchar
CASE pchar = [']
capnext = IIF((LEN(tempstr) - counter > 3), .T., .F.)
tempstr2 = tempstr2 + "'"
CASE pchar = "&"
tempstr2 = UPPER(tempstr)
EXIT
OTHERWISE
tempstr2 = tempstr2 + LOWER(pchar)
ENDCASE
counter = counter + 1
ENDDO
tempstr = tempstr2
ENDIF
IF AT("Mc", tempstr) = 1 .AND. LEN(TRIM(tempstr)) > 2
tempstr = "Mc" + UPPER(SUBSTR(tempstr, 3, 1)) + SUBSTR(tempstr, 4)
ENDIF
string = string + tempstr
ENDDO
string = TRIM(string)
RETURN
* EOP Icaps.PRG