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

Re: st: RE: RE: Converting char to ascii


From   "Andrew Felton" <afelton2@yahoo.com>
To   statalist@hsphsun2.harvard.edu
Subject   Re: st: RE: RE: Converting char to ascii
Date   Fri, 11 Mar 2005 01:17:58 -0000

Thank you, Nick.  I had been wondering if there was a built-in
function I wasn't aware of so that I could save writing a forval
i=32/255 loop, but I guess that probably goes pretty fast anyway.

Andrew

--- In statalist@yahoogroups.com, "Nick Cox" <n.j.cox@d...> wrote:
> di as txt `"`c'"' as res %6.0f `j' 
> 
> removes one bug. 
> 
> Nick 
> n.j.cox@d... 
> 
> > -----Original Message-----
> > From: owner-statalist@h...
> > [mailto:owner-statalist@h...]On Behalf Of Nick Cox
> > Sent: 10 March 2005 21:01
> > To: statalist@h...
> > Subject: st: RE: Converting char to ascii
> > 
> > 
> > I am not aware of a built-in. User-written functions 
> > are beyond my capabilities, but the following ado 
> > is a zeroth stab. Not tested much at all. 
> > 
> > program ascii, rclass  
> > 	version 8.2 
> > 	local l = length(`"`0'"') 
> > 	if `l' == 0 { 
> > 		di as err "nothing to do"
> > 		exit 498 
> > 	}
> > 	
> > 	forval i = 1/`l' { 
> > 		local c = substr(`"`0'"',`i',1) 
> > 		if `"`c'"' != " " {
> > 			local found 0 
> > 			forval j = 32/255 { 
> > 				if `"`c'"' == char(`j') { 
> > 					di as txt "`c'"  as res 
> > %6.0f `j'
> > 					local ascii "`ascii'`j' " 
> > 					local found 1 
> > 					continue, break 
> > 				}
> > 			}	
> > 			if !`found' { 
> > 				di as txt "`c' not known"
> > 				local ascii "`ascii'? " 
> > 			}	
> > 		}
> > 	}	
> > 	return local ascii "`ascii'" 
> > end 
> > 
> > 
> > 
> > Nick 
> > n.j.cox@d... 
> > 
> > > -----Original Message-----
> > > From: owner-statalist@h...
> > > [mailto:owner-statalist@h...]On Behalf Of 
> > > Andrew Felton
> > > Sent: 10 March 2005 20:20
> > > To: statalist@h...
> > > Subject: st: Converting char to ascii
> > > 
> > > 
> > > Hi,
> > > 
> > > Is there an inverse of the char() function?  So that I
> > > could get ascii("a") = 97?  -findit ascii- and a web
> > > search didn't seem to turn up anything.  Thank you,
> > > 
> > > Andrew Felton
> > > *
> > > *   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/
> > > 
> > 
> > *
> > *   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/
> > 
> 
> *
> *   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/



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