'=========================================================================== ' Subject: FORMAT TITLE Date: 12-02-98 (16:01) ' Author: Don Schullian Code: PB, PBCC ' Origin: d83@ath.forthnet.gr Packet: PB.ABC '=========================================================================== $if 0 ÚÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄ· PowerBASIC v3.50 ÚÄÄ´ DASoft ÇÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÂÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄ· ³ ÃÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄĶ Copyright 1998 ³ DATE: 1998-12-02 ÇÄ· ³ ³ FILE NAME FMTTITLE.BAS º by ÔÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÄ º º ³ ³ º Don Schullian, Jr. º º ³ ÔÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍͼ º º ÔÍÑÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍͼ º ÔÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍͼ There are 2 versions of the function fFormatTitle. The first one is for PowerBASIC v3.5 while the other is for PB/cc. All this function does is format an incoming string into a standard configuration that is used by titles. (eg: books, stories, songs) It ain't much but may come in handy now and again. eg: INCOMING: "The liTTle train That Could" RETURNING: "Little Train That Could, The" C'ya, ____ _ ____ ____ _____ | _ \ / \ / ___) __ | ___)(_ _) Don Schullian | |_) / _ \ \____\/ \| _) | | d83@DASoftVSS.com |____//_/ \_\(____/\__/|_| |_| www.DASoftVSS.com ___________________________________ www.basicguru.com Vertical Software Solutions $endif DECLARE FUNCTION fFormatTitle(BYVAL Title AS STRING) AS STRING $if 1 ' PowerBASIC v3.5 DIM T(5) AS STRING DIM X AS INTEGER CLS FOR X = 1 TO 5 READ T(X) NEXT FOR X = 1 TO 5 PRINT fFormatTitle(T(X)) NEXT DATA "The Bridge Over The River" DATA "A day in the park" DATA "An Answer to My Question" DATA "JUST 'ANOTHER' BOOK" DATA "i WAS HERE" FUNCTION fFormatTitle (BYVAL Title AS STRING) AS STRING DIM F AS LOCAL INTEGER DIM P AS LOCAL INTEGER 'position variable DIM Temp AS LOCAL STRING 'working string DIM T_ptr AS LOCAL BYTE PTR 'ptr to chars in Title$ ' Title = TRIM$(Title) 'strip all outside spaces WHILE INSTR(Title," ") > 0 'remove all double spaces REPLACE " " WITH " " IN Title ' WEND ' Title = LCASE$(Title) 'most obvious case ' P = INSTR(Title," ") 'find first space IF P > 0 AND P < 5 THEN 'check for 1st word RESTORE FormatTitleDATA ' set local data DECR P ' back up before the FOR F = 1 TO 3 ' check all 3 1st words READ Temp ' get the word IF LEFT$(Title,P) = Temp THEN ' if the first word then Title = MID$(Title,P+2) & ", " & Temp ' create the new title EXIT FOR ' all done! END IF ' NEXT ' END IF ' ' T_ptr = STRPTR32(Title) 'set the pointer F = 1 'set ucase flag for 1st char FOR P = 0 TO LEN(Title)-1 'check all other characters IF @T_ptr[P] = 32 THEN ' if a F = 1 ' set ucase flag ELSEif ISTRUE F THEN ' if ucase flag is set IF ( @T_ptr[P] > 96 ) AND _ ' if char is a -> z then ( @T_ptr[P] < 123 ) THEN ' BIT TOGGLE @T_ptr[P], 5 ' ' ucase the letter F = 0 ' reset the ucase flag END IF ' END IF ' NEXT ' ' FUNCTION = Title ' RETURN the formatted $ '--------------------------- FormatTitleDATA: ' local data DATA "a" ' the 1st words to be moved DATA "an" ' to the end the titles DATA "the" ' END FUNCTION $else ' PowerBASIC Console Compiler FUNCTION PBmain () DIM T AS LOCAL STRING DIM X AS LOCAL LONG FOR X = 1 TO DATACOUNT T = READ$(X) PRINT fFormatTitle(T) NEXT WAITKEY$ DATA "The Bridge Over The River" DATA "A day in the park" DATA "An Answer to My Question" DATA "JUST 'ANOTHER' BOOK" DATA "i WAS HERE" END FUNCTION FUNCTION fFormatTitle (BYVAL Title AS STRING) AS STRING DIM F AS LOCAL LONG DIM P AS LOCAL LONG 'position variable DIM Temp AS LOCAL STRING 'working string DIM T_ptr AS LOCAL BYTE PTR 'pointer to characters in Title string ' Title = TRIM$(Title) 'strip all outside spaces WHILE INSTR(Title," ") > 0 'remove all double spaces REPLACE " " WITH " " IN Title ' WEND ' Title = LCASE$(Title) 'most obvious case ' P = INSTR(Title," ") 'find first space IF P > 0 AND P < 5 THEN 'check for 1st word DECR P ' back up before the Temp = READ$(P) ' get the word we're looking for IF LEFT$(Title,P) = Temp THEN ' if it is the first word then Title = MID$(Title,P+2) & ", " & Temp ' create the new title END IF ' END IF ' ' T_ptr = STRPTR(Title) 'set the pointer F = 1 'set ucase flag for 1st character FOR P = 0 TO LEN(Title)-1 'check all other characters IF @T_ptr[P] = 32 THEN ' if a F = 1 ' set ucase flag ELSEif ISTRUE F THEN ' if ucase flag is set IF ( @T_ptr[P] > 96 ) AND _ ' if char is a -> z then ( @T_ptr[P] < 123 ) THEN ' BIT TOGGLE @T_ptr[P], 5 ' ' ucase the letter F = 0 ' reset the ucase flag END IF ' END IF ' NEXT ' ' FUNCTION = Title ' RETURN the formatted string '-------------------------------------------- DATA "a" ' the 1st words to be moved to the end of DATA "an" ' the titles DATA "the" ' END FUNCTION $endif