'=========================================================================== ' Subject: SEARCH AND REPLACE STRING Date: 12-24-96 (14:46) ' Author: Kurt Kuzba Code: QB, QBasic, PDS ' Origin: FidoNet QUIK_BAS Echo Packet: TEXT.ABC '=========================================================================== '> I already submitted a short program to search and replace '> instances of any combination of characters. (The person '> asking was asking for code to s/r %? codes.) (I didn't '> keep a copy of it.. darnit.... oh well.) '> I was basically saying that INSTR only tells you where '> the text starts at, as I interpreted the message as '> referring to INSTR searching and replacing... '>..... ' Right. You have to find the end of the word yourself. 'Since you already know the length of it, though, that is easy. '_|_|_| SANDR.BAS '_|_|_| A simple search and replace for QBasic strings. '_|_|_| No warrantee or guarantee is given or implied. '_|_|_| Released PUBLIC DOMAIN by Kurt Kuzba. (12/24/96) DECLARE SUB SandR (text$, OldT$, NewT$) PRINT CHR$(13); "Begin Search and Replace test." text$ = "Ellie's groovy boot reserves flavors" PRINT text$ OldWord$ = "boot": NewWord$ = "boy": rl% = LEN(OldWord$) SandR text$, "ellie's", "Every" PRINT text$ SandR text$, "groovy", "Good" PRINT text$ SandR text$, "boot", "Boy" PRINT text$ SandR text$, "reserves", "Deserves" PRINT text$ SandR text$, "flavors", "Favor" PRINT text$ SUB SandR (text$, OldT$, NewT$) rl% = LEN(OldT$): found% = INSTR(UCASE$(text$), UCASE$(OldT$)) IF found% THEN part1$ = "": IF found% > 1 THEN part1$ = LEFT$(text$, found% - 1) part2$ = MID$(text$, found% + rl%) text$ = part1$ + NewT$ + part2$ END IF END SUB '_|_|_| end SANDR.BAS