Stata The Stata listserver
[Date Prev][Date Next][Thread Prev][Thread Next][Date index][Thread index]

Re: st: file wrote single opening quote


From   Roger Newson <roger.newson@kcl.ac.uk>
To   statalist@hsphsun2.harvard.edu
Subject   Re: st: file wrote single opening quote
Date   Mon, 18 Nov 2002 17:14:45 +0000

At 15:43 18/11/02 +0000, Ulrich Kohler wrote:
Is there a way to wrote a single opening quote to a file with -file wrote-?

In a program I have the command

   file write texfile `"`line'"'

which wrotes the contents of the local macro `line' to the file handle
"texfile". The command works well except for lines which contains either a
local macro name (like `a') , or a single opening quote. In the first case
Stata expands the local macro name to the contents of the local macro. But I
want to have the local macro name (`a') in my file handle. In the second case
I got an error message because Stata thinks that there should be a valid
local macro name, which is not there.

I tried to escape each occurence of the single opening quote with the
backslash by substituting ` with \`. But

   local line: subinstr local line `"`"' `"\`"'

does not work for obvious reasons.  What else could be done?
I had essentially the same problem when I was writing my -intext- package (now downloadable from SSC - type -ssc describe intext-). The problem was discussed in a thread on Statalist, and a consensus seemed to emerge that the solution, in Stata as we know it, is to use -file- in binary mode (byte by byte) rather than text mode (line by line). You might like to look inside my -intext.ado- to see how I handled the awkward fact that a line of a text file is delimited by a linefeed under Unix, a carriage return under MacOS, and a carriage return and a line feed under Windows.

I hope this helps.

Roger




--
Roger Newson
Lecturer in Medical Statistics
Department of Public Health Sciences
King's College London
5th Floor, Capital House
42 Weston Street
London SE1 3QD
United Kingdom

Tel: 020 7848 6648 International +44 20 7848 6648
Fax: 020 7848 6620 International +44 20 7848 6620
or 020 7848 6605 International +44 20 7848 6605
Email: roger.newson@kcl.ac.uk

Opinions expressed are those of the author, not the institution.

*
* For searches and help try:
* http://www.stata.com/support/faqs/res/findit.html
* http://www.stata.com/support/statalist/faq
* http://www.ats.ucla.edu/stat/stata/




© Copyright 1996–2014 StataCorp LP   |   Terms of use   |   Privacy   |   Contact us   |   What's new   |   Site index