Determine if a string is numeric

From Rosetta Code
Revision as of 11:06, 24 August 2007 by rosettacode>UnpBk1

sony vaio a417m il sesto eroe packaging cosmetico euijeongbu cream. strange brew masterizzatore cd masterizzatore keys 49 usb av link spiderman o s t sito orologio breil vesna pisarovic ljubomora im so confused magazzino automatici un gioco xbox gratis per ogni amico legge 127 bassanini elezioni sorbolo universidad catolica del litoral historia del futbol fassi tecnica new terra regina allen, horatio fluorescente modding gratis s sct html golf tdi 2000 suzuki vitara 2.0 hdi ac dc donington copilul de aur si mihaela minune leinster soffiatori aspiratore cavalieri zodiaco ps2 lotus exige nortek dvd recorder vcr bugatto hub usb 2 0 autoalimentato toner hp 1100 stelle cadenti animazione recconti erotici illustrati www jobstreet com www wrestling it lultima mazurka fot gay gratis voglio volere di ligabue pagamenti effettuati bollo auto over the rainbow fax-lab 100 spigi vpd 351 tel aviv stock exchange ultimo marine decapitato www acupuntura decorazioni pasqua xer foto fi gay simulazioni terza prova alimentatore fuji gagl dymond drop golden heart giorgio de chirico logitech rally vibration feedback dvd philips 50 tomaz vs filterheadz when sorrow sang karena cinta joy tobing the sims fori tutti trucchi trucchi fifa 2004 sina dvd duran crazy burger four non blonds y miss you florin ricoh caplio gx8 cavalli camicia gioco di pallavolo per i bambini no adatto agli adulti giochi pokemon asus a3e tina turner army www sidi lave it mayara magri projeto pedagogico testo originale di don t tell me foto di britney spears nuda la ballata dei tre killers ngk candele maury, matthew fontaine ml 1210 toner i simpson stagione 5 palmare toshiba e740 tucano viaggio alba chaira classe a congelatori ocean taglio metalli belluno amstrad condizionatori e ventilatori video porno de michell vieth segretaria di hitler son of a preacher man abete bianco alberi smashing punkies terratec phase 22 funghetti un nuovo bacio pezzo accessori bmw i-pod mp3 apple kurg singles bando concorso guardia forestale 2004 a chi mi dice audio km0 mazda 6 diesel auto km 0 orario apertura banco di palermo cerchiamo superdotato hetai lesbo navigatore software bisazza, felice ok ilprezzo e giusto d-link dcs-5300w acquisto nome dominio samsung rt 34 supporto a ventosa auto mms suonerie samsung letteratura francese baudelaire fernanda romero odissea la orima cosa bella tette leccate da uomini maxtor - onetouch firewire da 200gb natt chanapa ac3 decoder yonca video girls hd 250 usb il violinista pazzo immagini anna laura ribas mozart in egypt modem adsl2 linksys 12 mbps nomad amplificatore marantz amplificatori popso it lennox zion monitor 930mp produccion animal azienda spedizione codec xp irdeto2 key traduzione e testo fuck it pellworm placanica pvr 150 disem a nisam ziv hack muonline lacoste amateur facials r507 l antisociale ti voglio vero sardo g new atletic suzuki vitara 2.0 tdi s.w. alagoinhas inno italia cyclette offerta sega europe si dedica al biliardo sidney poitier ascolta canzoni sanremo 1990 www radiozeta it jota queste jules berry cd turin brakes voli charter centro foto grafico snc gu seggiolini per auto e bicicletta wisiny yandel spinning ozone dragosta din tei mouse wifi buscar en el google air max 2003 argento renault clio 16v lesli et sobri icq 2004 red e toby nemiciamici buste imbottite hp deskjet 970cxi eric pridz call on me www tettona it felikszone pancreas par condicio monaco di baviera renault dci 100 trucchi pc blitz wwe pics tuta nike classic r viviani immagini dei peni piu lunghi del mondo tam tam network

Task
Determine if a string is numeric
You are encouraged to solve this task according to the task description, using any language you may know.

Demonstrates how to implement a custom IsNumeric method.

Ada

The first file is the package interface containing the declaration of the Is_Numeric function.

package Numeric_Tests is
   function Is_Numeric(Item : in String) return Boolean;
end Numeric_Tests;

The second file is the package body containing the implementation of the Is_Numeric function.

package body Numeric_Tests is

   ----------------
   -- Is_Numeric --
   ----------------

   function Is_Numeric (Item : in String) return Boolean is
      Result : Boolean := True;
   begin
      declare
         Int : Integer;
      begin
         Int := Integer'Value(Item);
      exception
         when others =>
            Result := False;
      end;
      if Result = False then
         declare
            Real : Float;
         begin
            Real := Float'Value(Item);
            Result := True;
         exception
            when others =>
               null;
         end;
      end if;
      return Result;
   end Is_Numeric;

end Numeric_Tests;

The last file shows how the Is_Numeric function can be called.

with Ada.Text_Io; use Ada.Text_Io;
with Numeric_Tests; use Numeric_Tests; 

procedure Isnumeric_Test is
   S1 : String := "152";
   S2 : String := "-3.1415926";
   S3 : String := "Foo123";
begin
   Put_Line(S1