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

RE: st: RE: file wrote single opening quote


From   "Nick Cox" <n.j.cox@durham.ac.uk>
To   <statalist@hsphsun2.harvard.edu>
Subject   RE: st: RE: file wrote single opening quote
Date   Mon, 18 Nov 2002 16:01:20 -0000

Ulrich Kohler
> 
> > use _char(96)
> 
> 
> This don't works for me. I got the macro `line' from -file 
> read-. The file I 
> read may contain lines with single quotes and/or macro 
> names. To wrote this 
> line (after some selections and/or replacements) to another 
> file I use file 
> write. To use the _char(96)-solution I need to substitute 
> single opening 
> quotes with something like:
> 
> local line: subinstr local line `"`"' `"_char(96)"'
> 
> which does not work. 
> 
> Here is a (very) simple example of the problem. Consider the 
> following sequence: 
> 
>   file open texfile using saving.tex, replace write text
>   file open dofile using using.do, read text
>   file read dofile line 
>   while r(eof)==0 {
>     file write texfile _n `"`line'"'
>     file read dofile line
>   }
>   file close dofile
>   file close texfile
> 
> This should "copy" the file using.do to the file 
> "saving.tex" line by line. 
> It works---but not for lines with local macros... 
> 

Agreed. And this broad problem has bitten others 
as well, including Kit Baum, Roger Newson 
and myself. What we need is some way of inhibiting 
Stata from interpreting the local macro, and 
the only way to progress might be to read in the 
file as binary. Nick Winter has some code which 
you might want to look at. 

Alternatively, it might be easier to do this 
outside Stata: Awk, Perl, Python, whatever. 

If there's some character you never use normally, 
a combination approach might be to map ` to 
that character, do most of the processing 
in Stata, and then reverse the mapping. 

Nick 
n.j.cox@durham.ac.uk 

*
*   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