Statalist The Stata Listserver


[Date Prev][Date Next][Thread Prev][Thread Next][Date index][Thread index]

st: RE: Trying to do inverse of char(n) without Mata ascii()


From   "Nick Cox" <n.j.cox@durham.ac.uk>
To   <statalist@hsphsun2.harvard.edu>
Subject   st: RE: Trying to do inverse of char(n) without Mata ascii()
Date   Sat, 10 Jun 2006 20:15:46 +0100

A problem with this is likely to be that the tab 
character maps to multiple spaces, so messing up
your counting. 

But in terms of your immediate question, look 
again at 

strpos(`"`charorder'""', "a")

The first five quotes read off (d = double, s = single, q = quote) 
	`"          left compound d.q. 
	`		left s.q. 
	'           right s.q. 
	"	      d.q. 
	"'          right compound d.q. 
and are thus, as Stata says, not balanced. 

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

Mike Lacy
 
> I was trying implement a code fragment to give the number of a given 
> character, i.e., the inverse of char(n) without using the Mata ascii 
> function. (One of my reasons for doing it is that I am annoyed by the 
> idea that this is not simply an ordinary function in Stata.)  So, I 
> tried the following:
> 
> *Construct a list of all the characters in order
> local charorder = ""
> forval i = 1/255 {
>    local c = char(`i')
>    if `i' ~= 96 {  /* avoid the pesky open-quote */
>       local charorder = `"`charorder'`c'"'
>    }
>    else {   /* stick in a stand in */
>       local charorder = `"`charorder'zzz"'
>    }
> }
> local charorder = subinstr(`"`charorder'"', "zzz", "`",1)
> *
> di " The whole list:   " `"`charorder""'
> * try finding something
> di "Letter a is found at ", strpos(`"`charorder'""', "a")
> 
> While there may well be a more elegant way to get the open-quote 
> character into a macro that also contains " and ', what I am most 
> stuck with is the very last line, in which I tried to use strpos to 
> find the position of a
> sample character, and the response is "too few quote," which 
> presumably is the interpreter's complaint about 
> `"`charorder'""'  in strpos().
> Any suggestions here?

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