BBS: Inland Empire Archive Date: 05-12-92 (11:56) Number: 10 From: DAVID POSKIE Refer#: NONE To: EDDIE ROWE Recvd: NO Subj: Firstcaps Function Conf: (2) Quik_Bas
On 05-10-92 EDDIE ROWE wrote to ALL... ER> I'm trying to write a routine that will take a string from another ER> program which converts everything to ALL CAPS back to a form that ER> is more pleasing to the eye. This relys on the string having two ER> components (in my case a FirstName LastName). Anyone have a pointer or ER> two to share to clean this up so it can take however many different ER> parts its needs and maybe a bit simpler? Here's what I'm using, thanks to code from Zack Jones: ' CAPWORDS.BAS -- demonstrates FirstCap$() function ' inspired by code furnished by Zack Jones DEFINT A-Z DECLARE FUNCTION FirstCap$ (Temp$) CLS Temp$ = "-> ZACK jones supplied the code to dO THIS." PRINT Temp$ PRINT FirstCap$(Temp$) END FUNCTION FirstCap$ (Temp$) ' FirstCap$ function removes leading & trailing blanks from ' its string argument, then converts each word in the string ' to an initial uppercase letter followed by all lowercase. ' Temp$ = LTRIM$(RTRIM$(Temp$)) IF Temp$ = "" THEN Work$ = "" ELSE ' Search for words inside the string. NextWord% = 1 DO Index% = INSTR(NextWord%, Temp$, " ") IF Index% <> 0 THEN NowWord$ = MID$(Temp$, NextWord%, Index% - NextWord%) NextWord% = Index% + 1 ELSE NowWord$ = MID$(Temp$, NextWord%) END IF ' Capitalize first letter & convert remainder to lower case NowWord$ = UCASE$(LEFT$(NowWord$, 1)) + LCASE$(MID$(NowWord$, 2)) IF Index% THEN NowWord$ = NowWord$ + " " Work$ = Work$ + NowWord$ LOOP UNTIL Index% = 0 END IF FirstCap$ = Work$ END FUNCTION ' Enjoy - and thanks, Zack! ... OFFLINE 1.36 * Whatever is well conceived can be well expressed. --- MsgToss 2.0c (r) * Origin: JW-PC Consulting DataFlex.HST (608)837-1923 (1:121/8)
Books at Amazon:
Back to BASIC: The History, Corruption, and Future of the Language
Hackers: Heroes of the Computer Revolution (including Tiny BASIC)
Go to: The Story of the Math Majors, Bridge Players, Engineers, Chess Wizards, Scientists and Iconoclasts who were the Hero Programmers of the Software Revolution
The Advent of the Algorithm: The Idea that Rules the World
Moths in the Machine: The Power and Perils of Programming
Mastering Visual Basic .NET