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

st: RE: RE: Converting char to ascii


From   "Nick Cox" <[email protected]>
To   <[email protected]>
Subject   st: RE: RE: Converting char to ascii
Date   Thu, 10 Mar 2005 21:17:09 -0000

di as txt `"`c'"' as res %6.0f `j' 

removes one bug. 

Nick 
[email protected] 

> -----Original Message-----
> From: [email protected]
> [mailto:[email protected]]On Behalf Of Nick Cox
> Sent: 10 March 2005 21:01
> To: [email protected]
> 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 
> [email protected] 
> 
> > -----Original Message-----
> > From: [email protected]
> > [mailto:[email protected]]On Behalf Of 
> > Andrew Felton
> > Sent: 10 March 2005 20:20
> > To: [email protected]
> > 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/



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