|  |  | 
[Date Prev][Date Next][Thread Prev][Thread Next][Date index][Thread index]
st: Trying to do inverse of char(n) without Mata ascii()
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?
Regards,
=-=-=-=-=-=-=-=-=-=-=-=-=
Mike Lacy
Fort Collins CO USA
(970) 491-6721 office
*
*   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/