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   Ulrich Kohler <>
Subject   Re: st: RE: file wrote single opening quote
Date   Mon, 18 Nov 2002 16:49:30 +0000

Nick Cox  wrote
> Ulrich Kohler
> > 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.

> 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, 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 to the file "saving.tex" line by line. 
It works---but not for lines with local macros... 


*   For searches and help try:

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