View Single Post
Old 01-23-2007, 07:25 AM   #1
Puffball doesn't litterPuffball doesn't litter
Puffball's Avatar
Posts: 20
Karma: 181
Join Date: Jan 2007
Location: Scotland, UK
Device: Sony Reader
BASIC program for smart quotes

I have been reformatting Gutenberg texts, and wanted to change straight quote marks (CHR$34 and CHR$39) to the curly ones (ASCII codes vary).

I do not have MS Word on my PC, only OpenOffice and WordPad. On my elderly Mac, which does have Word, using find-and-replace to turn plain quotation marks into curly ones gives problems. Single quote-marks next to double-quotes are sometimes wrong. Also, smart-quote algorithms don't know how to handle an open-single-quote at the start of a word, when that quote indicates a missing syllable.

So I wrote a very simple, not to say clunky, BASIC program to help. It definitely runs under QBasic in a DOS window under Windows XP, but will probably be OK in QuickBasic, etc., as well.

Before you start, give your text file a DOS-friendly (i.e. 8+3) name.

The program produces a new version of it, called OUTPUT.TXT, in the current directory. The quote marks are converted as follows:

Opening double quote: {odq}
Closing double quote: {cdq}
Opening single quote: {osq}
Closing single quote: unchanged (')
Single quote needing human attention: {?}

It also flags (as "{[char]}"characters with an ASCII code greater than 126; this is handy when converting other text files which may contain accents and whatnot.

Then all you have to do is find-and-replace on {odq}, {cdq}, {osq}, and '. When you're done, a search for "{" or "}" will reveal anything else that needs your attention.

[Note for people even less computer-literate than me ... there must be a few out there ... Cut and paste the text from "REM Quotes.bas" down to "END" and save it as "QUOTES.BAS"]

I hope this is found useful!

REM Quotes.bas
REM Flags text files for quotes
REM 23 Jan 07

PRINT "Flags text files for quotation marks"
INPUT "Which file do you want to process? ", file$

tempfile$ = "output.txt"

OPEN tempfile$ FOR OUTPUT AS #2


prevchar$ = ""

char$ = INPUT$(1, #1)
IF char$ > "~" THEN char$ = "{"+char$+"}"
IF char$ = CHR$(34) AND prevchar$ = CHR$(10) THEN char$ = "{odq}"
IF char$ = CHR$(34) AND prevchar$ = " " THEN char$ = "{odq}"
IF char$ = CHR$(34) THEN char$ = "{cdq}"
IF char$ = CHR$(39) AND prevchar$ = CHR$(10) THEN char$ = "{osq}"
IF char$ = CHR$(39) AND prevchar$ = " " THEN char$ = "{osq}"
IF char$ = CHR$(39) AND prevchar$ = "{odq}" THEN char$ = "{?}"
PRINT #2, char$;
prevchar$ = char$


PRINT "Done"

Last edited by Puffball; 01-23-2007 at 05:01 PM. Reason: Forgot something ...
Puffball is offline   Reply With Quote