Re: Converting string to numerical data - regardless of errors
Posted in 1994
kerry@kcbbs.gen.nz (Kerry Sainsbury) writes: >In article <39bniu$kci@emory.mathcs.emory.edu>, >kestnb!mdk@uunet.uu.net (Michael Kastler) wrote: >Regarding checking if a string is numeric: >> variable crashes the program. I really, really don't want to turn on >> error trapping for the program - does anyone know of any way to check >> if specific data is numerical or text or a way to convert any text to a >> form that is handleable by an integer variable (such as turning all >> text into 0's or even their ascii codes would be acceptable)? >You don't have to remove error handling for long! >... If you insist on not doing via trapping, you could test each character position FUNCTION is_number(l_text) DEFINE l_text CHAR(50) # Cope with looong numbers! DEFINE x SMALLINT IF LENGTH(l_text) = 0 THEN # nothing to check RETURN l_text END IF FOR x = 1 TO LENGTH(l_text) IF l_text[x] NOT MATCHES "[0123456789]" THEN # change any "bad" character to 0 LET l_text[x] = "0" END IF END FOR RETURN l_text END FUNCTION ======================================================================= Dennis J. Pimple dennisp@informix.com Opinions expressed Senior Consultant -------------------- are mine, and do not Informix Software Inc Voice: 303-850-0210 necessarily reflect Denver Colorado USA Fax: 303-779-4025 those of my employer.