Determine if a string is numeric: Difference between revisions

From Rosetta Code
Content added Content deleted
mNo edit summary
Line 1: Line 1:
[http://agodichik.angelfire.com/styles/patapam.htm patapam] [http://webancks.at.tut.by/images/small/igrometro-capello.htm igrometro capello] [http://kibrumfik.at.tut.by/text/directory/lettini-fasciatoi.htm lettini fasciatoi] [http://konstantinkar.ifrance.com/description/riso-bianco/ riso bianco] [http://kataevka.ifrance.com/articles/batteria-nokia/ batteria nokia 9210 i] [http://macertot.ifrance.com/view/offerta-computer.htm offerta computer] [http://ariadnafeni.ifrance.com/resources/www-alessio/ www alessio it] [http://wipitts.at.tut.by/text/directory/divas.htm divas] [http://gaburlei.angelfire.com/resources/immagini-inedite.htm immagini inedite per gran turismo 4] [http://webancks.at.tut.by/images/small/stampante-epson.htm stampante epson stylus color] [http://konstantinkar.ifrance.com/description/donne-mature/ donne mature anziane troie] [http://dylantian.ifrance.com/styles/cubical-quad.htm cubical quad] [http://brandalinden.ifrance.com/topic/onar-o.htm onar o 347 ka] [http://dweejah.ifrance.com/new/tito-puente/ tito puente lyrics] [http://jrosestar.ifrance.com/html/atlantic-city/ atlantic city usa] [http://ariadnafeni.ifrance.com/resources/un-trailer/ un trailer per battlefield command] [http://dylantian.ifrance.com/styles/navman-pocket.htm navman pocket pc] [http://kataevka.ifrance.com/articles/uomo-perfetto/ uomo perfetto] [http://alena344.ifrance.com/text/seneca/ seneca] [http://dweejah.ifrance.com/new/hard-disk/ hard disk con lettore compact flash] [http://isabellaval.ifrance.com/isole-vacanze/ isole vacanze] [http://feralpaw-omm.ifrance.com/html/pamukkale/ pamukkale] [http://macertot.ifrance.com/view/guem.htm guem] [http://wiwoolle.at.tut.by/content/view/toner-epson.htm toner epson epl 5700] [http://pohogue.angelfire.com/library/frigorifero-da.htm frigorifero da incasso monoporta] [http://rebuckma.angelfire.com/description/love-energy.htm love energy] [http://spkleins.angelfire.com/trolley/ trolley 50] [http://hewvey.ifrance.com/library/camping-gear/ camping gear] [http://yvharlen.at.tut.by/lib/testi-hit.htm testi hit mania dance 2004] [http://hewvey.ifrance.com/library/palermo-coppie/ palermo coppie] [http://alena344.ifrance.com/text/caricatore-pioneer/ caricatore pioneer autoradio] [http://casloan.angelfire.com/small/primier-impacto/ primier impacto] [http://macertot.ifrance.com/view/http-www.htm http www publiweb porno gratis] [http://hehalley.at.tut.by/content/view/theme-park.htm theme park world] [http://spkleins.angelfire.com/hi-q/ hi q gasca me] [http://hewvey.ifrance.com/library/diamond-music/ diamond music] [http://nymphbmbzl222.ifrance.com/ytunnel.htm ytunnel] [http://wifry.angelfire.com/styles/toner-smaltimento.htm toner smaltimento] [http://brandalinden.ifrance.com/topic/hector-y.htm hector y tito y noriega] [http://hewvey.ifrance.com/library/manziana/ manziana] [http://spkleins.angelfire.com/sesso-ingoio/ sesso ingoio gratis] [http://isabellaval.ifrance.com/polistirolo-brindisi/ polistirolo brindisi] [http://jrosestar.ifrance.com/html/prole/ prole] [http://brandalinden.ifrance.com/topic/flipper-telesystem.htm flipper telesystem] [http://macertot.ifrance.com/view/bed-platform.htm bed platform] [http://kataevka.ifrance.com/articles/tv-lcd/ tv lcd sony 1366x768] [http://nymphbmbzl222.ifrance.com/equinox.htm equinox] [http://jrosestar.ifrance.com/html/jamie-lee/ jamie lee kurtis] [http://konstantinkar.ifrance.com/description/innsbruck-alberghi/ innsbruck alberghi e hotel] [http://kataevka.ifrance.com/articles/sam-group/ sam group] [http://konstantinkar.ifrance.com/description/tutte-le/ tutte le carte magic] [http://wipitts.at.tut.by/text/directory/batteria-npfr.htm batteria npfr1] [http://dweejah.ifrance.com/new/abbonamento-periodico/ abbonamento periodico] [http://kedewber.at.tut.by/topic/tvixmu-gb.htm tvixm3000u 160gb] [http://hewvey.ifrance.com/library/utility-video/ utility video multimedia] [http://webancks.at.tut.by/images/small/lavoro-rivoli.htm lavoro rivoli] [http://ariadnafeni.ifrance.com/resources/rober-hatemo/ rober hatemo gurur] [http://nymphbmbzl222.ifrance.com/sassofono-blu.htm sassofono blu] [http://beyonddreamingx.angelfire.com/content/corsa-di.htm corsa di macchine] [http://agodichik.angelfire.com/styles/gas-piccolo.htm gas piccolo riscaldamento] [http://kairikekui.ifrance.com/resources/fabrizio-de/ fabrizio de andre raccolta] [http://ariadnafeni.ifrance.com/resources/che-tettone/ che tettone] [http://konstantinkar.ifrance.com/description/ufficio-arredato/ ufficio arredato] [http://sagaddy.angelfire.com/styles/bangkok-intrattenimento/ bangkok intrattenimento] [http://hewvey.ifrance.com/library/tinto-fermo/ tinto fermo posta] [http://isabellaval.ifrance.com/last-christmas/ last christmas degli wham] [http://wifry.angelfire.com/styles/tabulati-musica.htm tabulati musica rock] [http://pohogue.angelfire.com/library/lettore-dvd.htm lettore dvd divx roadstar] [http://alena344.ifrance.com/text/banja/ banja] [http://hewvey.ifrance.com/library/nuove-immagini/ nuove immagini e video per top spin] [http://snerma.angelfire.com/text/just-i/ just i can t wait until] [http://feralpaw-omm.ifrance.com/html/gara-di/ gara di graffiti] [http://nymphbmbzl222.ifrance.com/gestione-orari.htm gestione orari turnisti] [http://gaburlei.angelfire.com/resources/moore-demi.htm moore demi] [http://wifry.angelfire.com/styles/lampade-di.htm lampade di emergenza] [http://brandalinden.ifrance.com/topic/uscita-dv.htm uscita dv videocamere] [http://dweejah.ifrance.com/new/mp-radio/ mp3 radio fm] [http://dylantian.ifrance.com/styles/nuova-opel.htm nuova opel auto nuove] [http://gaburlei.angelfire.com/resources/renault-.htm renault 19 16v] [http://dweejah.ifrance.com/new/rosana-diaz/ rosana diaz] [http://gaburlei.angelfire.com/resources/trucchi-gt.htm trucchi gt3 ps2] [http://thmastrie.angelfire.com/resources/b-m.htm b m x] [http://hewvey.ifrance.com/library/mercedes-ml/ mercedes ml nuove] [http://agodichik.angelfire.com/styles/quart.htm quart] [http://jrosestar.ifrance.com/html/una-fortuna/ una fortuna da morire] [http://crhighto.at.tut.by/img/styles/in-campeggio.htm in campeggio a beverly hills] [http://isabellaval.ifrance.com/come-fare/ come fare pompini] [http://mcunderh.at.tut.by/resources/articles/toner-konica.htm toner konica 1120] [http://dweejah.ifrance.com/new/bravo-club/ bravo club it] [http://konstantinkar.ifrance.com/description/storia-di/ storia di question mark] [http://wipitts.at.tut.by/text/directory/flash-pen.htm flash pen drive memory card] [http://pohogue.angelfire.com/library/biesiada.htm biesiada] [http://lidresze.angelfire.com/blog/bruciatori-barbecue.htm bruciatori barbecue e accessori] [http://wifry.angelfire.com/styles/quanla.htm quanla] [http://hehalley.at.tut.by/content/view/promesse-di.htm promesse di marinaio] [http://alena344.ifrance.com/text/radeon-xxt/ radeon x850xt 256mb] [http://brandalinden.ifrance.com/topic/tipsy-j.htm tipsy j kwon] [http://dweejah.ifrance.com/new/hitachi-/ hitachi 160 gb] [http://brandalinden.ifrance.com/topic/sex.htm sex10] [http://jrosestar.ifrance.com/html/super-cazzone/ super cazzone] [http://royal-g.kiushapo.cn royal g galos] [http://immaggini-d.sound-of-sun.cn immaggini d piscine] [http://copertina-di.sound-of-sun.cn copertina di resto in ascolto] [http://web-sorting.cn/nettuno-astronomia.htm nettuno (astronomia)] [http://keokepa.com.cn/mixer.htm mixer 4] [http://muro-philips.digirb-backward.cn muro philips] [http://nadzor-ns.cn/mikela.htm mikela] [http://calcetto-a.happi-thoughts.org.cn calcetto a 5 femminile] [http://keokepa.com.cn/sex-con.htm sex con ragazze che vanno a scuola] [http://panasonic-kxtcaexm.happi-thoughts.org.cn panasonic kxtca151exm] [http://nonkomformist.cn/rodolfo-gaitan.htm rodolfo gaitan castro] [http://nadzor-ns.cn/sunny-cruz.htm sunny cruz] [http://custine-adolphe.jowugow.cn custine adolphe] [http://keokepa.com.cn/giochi-x.htm giochi x box] [http://web-sorting.cn/ballerine-per.htm ballerine per feste private] [http://reminder.sound-of-sun.cn reminder] [http://frankee-fuck.fast-girl.net.cn frankee fuck back] [http://pixie-bite.org.cn/il-settecento.htm il settecento] [http://mama-kin.sound-of-sun.cn mama kin] [http://daniele-prende.kiushapo.cn daniele prende il treno] [http://georgiil.net.cn/cersaie.htm cersaie] [http://pixie-bite.org.cn/scheda-grafica.htm scheda grafica dual] [http://feltrinelli.kiushapo.cn feltrinelli] [http://dustybooks.cn/miglior-prezzo.htm miglior prezzo cellulare nokia 6600] [http://knuckles-lives.cn/il-soldato.htm il soldato innammorato] [http://knuckles-lives.cn/sette-ore.htm sette ore di guai] [http://georgiil.net.cn/raghav.htm raghav] [http://dustybooks.cn/la-rosa.htm la rosa di jericho] [http://serenissima-t.taliabriscoe.cn serenissima t f vs moltosugo] [http://knuckles-lives.cn/mpgo-per.htm mp3go per nokia 3650] [http://margaret-hassan.mack-si.cn margaret hassan morte] [http://waltermoney.cn/unione-provinciale.htm unione provinciale artigiani di padova] [http://web-sorting.cn/youre-under.htm youre under arrest the movie] [http://ixus.panzerfausts.com.cn ixus 400] [http://web-sorting.cn/ventole-x.htm ventole 80x80] [http://keokepa.com.cn/motto-mini.htm motto mini] [http://foto-pornostar.sound-of-sun.cn foto pornostar famose] [http://bob-x.taliabriscoe.cn bob x] [http://philips-cd.kiushapo.cn philips 3cd mp3] [http://nadzor-ns.cn/cardio-on.htm cardio on line srl] [http://una-sposa.greylopht.cn una sposa per mao] [http://fierydarknez.cn/annuncio-personali.htm annuncio personali foto] [http://silenzio-militare.greylopht.cn silenzio militare] [http://web-sorting.cn/satanik.htm satanik] [http://dustybooks.cn/www-gdif.htm www gdif it] [http://locandine-film.kiushapo.cn locandine film dvd gratis] [http://benassi-bros.taliabriscoe.cn benassi bros i love my sex] [http://nonkomformist.cn/bianco-con.htm bianco con il giallo spartito] [http://georgiil.net.cn/secondo-aggiornamento.htm secondo aggiornamento disponibile per ghost recon 2] [http://feliz-navidad.happi-thoughts.org.cn feliz navidad] [http://nonkomformist.cn/thermaltake-tr.htm thermaltake tr2] [http://stufe-in.taliabriscoe.cn stufe in maiolica] [http://nonkomformist.cn/www-netmeeting.htm www netmeeting it] [http://leslie-cheung.fast-girl.net.cn leslie cheung] [http://buscopan.digirb-backward.cn buscopan] [http://finanziamento-nuoro.digirb-backward.cn finanziamento nuoro] [http://datteln.taliabriscoe.cn datteln] [http://hp-batteria.mack-si.cn hp batteria nx6110] [http://dvdr-x.sound-of-sun.cn dvdr 8x datawrite] [http://nonkomformist.cn/jeans-calvin.htm jeans calvin klein uomo] [http://nonkomformist.cn/ganoderma.htm ganoderma] [http://waltermoney.cn/foto-sfondi.htm foto sfondi cavalli] [http://dustybooks.cn/siliconi.htm siliconi] [http://nadzor-ns.cn/nuova-tucson.htm nuova tucson auto km 0] [http://georgiil.net.cn/ballata-in.htm ballata in blu] [http://motoracer.digirb-backward.cn motoracer 2] [http://caricabatterie-sony.taliabriscoe.cn caricabatterie sony] [http://pixie-bite.org.cn/pctv-e.htm pctv 200e] [http://georgiil.net.cn/bulloneria.htm bulloneria] [http://nonkomformist.cn/case-vacanza.htm case vacanza capri] [http://pixie-bite.org.cn/stilografica.htm stilografica] [http://nonkomformist.cn/tvc-lcd.htm tvc lcd 32 samsung] [http://ganguro-girl.happi-thoughts.org.cn ganguro girl] [http://o-zone.taliabriscoe.cn o zone dragostea din tei remix version] [http://calendario-flavio.happi-thoughts.org.cn calendario flavio montrucchio] [http://funeral-of.panzerfausts.com.cn funeral of heart] [http://bataille-henry.greylopht.cn bataille henry] [http://web-sorting.cn/musique-gratuite.htm musique gratuite] [http://dustybooks.cn/thomson-mp.htm thomson mp3 20gb] [http://knuckles-lives.cn/combattimenti.htm combattimenti] [http://keokepa.com.cn/dieta-anti.htm dieta anti colesterolo] [http://keokepa.com.cn/senza-tubo.htm senza tubo] [http://knuckles-lives.cn/severina-vukovic.htm severina vukovic video] [http://fierydarknez.cn/www-tintuc.htm www tintuc vn] [http://web-sorting.cn/run-dmc.htm run dmc together forever greatest hits 1983 2000] [http://nikon.kiushapo.cn nikon custodia subacquea] [http://re-centrino.greylopht.cn r50e centrino] [http://georgiil.net.cn/epson-color.htm epson color 1500] [http://pixie-bite.org.cn/cartina-stradale.htm cartina stradale londra] [http://keokepa.com.cn/latte-in.htm latte in polvere mellin] [http://web-sorting.cn/sd-io.htm sd io] [http://dvd-recorder.kiushapo.cn dvd recorder rh7500] [http://traduttori-danese.panzerfausts.com.cn traduttori danese] [http://eminflex.panzerfausts.com.cn eminflex] [http://dvd-decrypter.mack-si.cn dvd decrypter download] [http://vini-friuli.mack-si.cn vini friuli] [http://pixie-bite.org.cn/annuncio-toscana.htm annuncio toscana] [http://nadzor-ns.cn/carta-credito.htm carta credito bancaria] [http://ivy-quins.mack-si.cn ivy quins] [http://waltermoney.cn/everybody-s.htm everybody s gotta learn sometimes beck] {{task}}
{{task}}
Demonstrates how to implement a custom IsNumeric method.
Demonstrates how to implement a custom IsNumeric method.


Line 50: Line 50:
S3 : String := "Foo123";
S3 : String := "Foo123";
begin
begin
Put_Line(S1 & " results in " & Boolean'Image(Is_Numeric(S1)));
Put_Line(S1
Put_Line(S2 & " results in " & Boolean'Image(Is_Numeric(S2)));
Put_Line(S3 & " results in " & Boolean'Image(Is_Numeric(S3)));
end Isnumeric_Test;
The output of the program above is:
152 results in TRUE
-3.1415926 results in TRUE
Foo123 results in FALSE

==[[C]]==
[[Category:C]]

Returns true (non-zero) if character-string parameter represents a signed or unsigned integer.
Otherwise returns false (zero).

#include <stdlib.h>
int isNumeric (const char * s)
{
char * p;
strtol (s, &p, 10);
return !*p;
}

==[[C sharp|C#]]==
[[Category:C sharp|C#]]

'''Framework:''' [[.NET]] 2.0+
public static bool IsNumeric(string s)
{
double Result;
return double.TryParse(s, out Result); // TryParse routines were added in Framework version 2.0.
}
string value = "123";
if (IsNumeric(value))
{
// do something
}

'''Framework:''' [[.NET]] 1.0+

using System.Text.RegularExpressions;
public static bool IsNumeric(string s)
{
try
{
Double.Parse(s);
return true;
}
catch
{
return false;
}
}

==[[ColdFusion]]==
[[Category:ColdFusion]]

Adobe's ColdFusion

<cfset TestValue=34>
TestValue: <cfoutput>#TestValue#</cfoutput><br>
<cfif isNumeric(TestValue)>
is Numeric.
<cfelse>
is NOT Numeric.
</cfif>

<cfset TestValue="NAS">
TestValue: <cfoutput>#TestValue#</cfoutput><br>
<cfif isNumeric(TestValue)>
is Numeric.
<cfelse>
is NOT Numeric.
</cfif>

==[[Forth]]==
[[Category:Forth]]
'''Interpreter:''' gforth 0.6.2

: is-numeric ( addr len -- )
2dup snumber? ?dup if \ not standard, but >number is more cumbersome to use
0< if
-rot type ." as integer = " .
else
2swap type ." as double = " <# #s #> type
then
else 2dup >float if
type ." as float = " f.
else
type ." isn't numeric in base " base @ dec.
then then ;
s" 1234" is-numeric \ 1234 as integer = 1234
s" 1234." is-numeric \ 1234. as double = 1234
s" 1234e" is-numeric \ 1234e as float = 1234.
s" $1234" is-numeric \ $1234 as integer = 4660 ( hex literal )
s" %1010" is-numeric \ %1010 as integer = 10 ( binary literal )
s" beef" is-numeric \ beef isn't numeric in base 10
hex
s" beef" is-numeric \ beef as integer = BEEF
s" &1234" is-numeric \ &1234 as integer = 4D2 ( decimal literal )

==[[IDL]]==
[[Category:IDL]]

function isnumeric,input
on_ioerror, false
test = double(input)
return, 1
false: return, 0
end

Could be called like this:

if isnumeric('-123.45e-2') then print, 'yes' else print, 'no'
; ==> yes
if isnumeric('picklejuice') then print, 'yes' else print, 'no'
; ==> no

==[[Java]]==
[[Category:Java]]
It's generally bad practice in Java to rely on an exception being thrown since exception handling is relatively expensive. If non-numeric strings are common, you're going to see a huge performance hit.
public boolean isNumeric(String input) {
try {
Integer.parseInt(input);
return true;
}
catch (NumberFormatException e) {
// s is not numeric
return false;
}
}

Alternative 1 : Check that each character in the string is number. Note that this will only works for integers.

private static final boolean isNumeric(final String s) {
for (int x = 0; x < s.length(); x++) {
final char c = s.charAt(x);
if (x == 0 && (c == '-')) continue; // negative
if ((c >= '0') && (c <= '9')) continue; // 0 - 9
return false; // invalid
}
return true; // valid
}

Alternative 2 : use a regular expression (a more elegant solution). Also, only for integers.

public static boolean IsNumeric(string inputData) {
final static Regex isNumber = new Regex(@"^-{0,1}\d+$");
Match m = isNumber.Match(inputData);
return m.Success;
}

==[[JavaScript]]==
[[Category:JavaScript]]

string value = "123.45e7";
if (isFinite(value))
{
// do something
}
//Or, in web browser in URL box:
// javascript:value="123.45e4"; if(isFinite(value)) {alert('numeric')} else {alert('non-numeric')}


==[[mIRC Scripting Language]]==
[[Category:mIRC Scripting Language]]
'''Interpreter:''' [[mIRC]]

var %value = 3
if ($1 isnum) {
echo -s $1 is numeric.
}

==[[Objective-C]]==
[[Category:Objective-C]]
'''Compiler:''' [[GNU Compiler Collection|gcc]]
[[Category:GNU Compiler Collection]]

The ''NSScanner'' class supports scanning of strings for various types. The ''scanFloat'' method will return TRUE if the string is numeric, even if the number is actually too long to be contained by the precision of a ''float''.

if( [[NSScanner scannerWithString:@"-123.4e5"] scanFloat:nil] )
NSLog( @"\"-123.4e5\" is numeric" );
else
NSLog( @"\"-123.4e5\" is not numeric" );
if( [[NSScanner scannerWithString:@"Not a number"] scanFloat:nil] )
NSLog( @"\"Not a number\" is numeric" );
else
NSLog( @"\"Not a number\" is not numeric" );
// prints: "-123.4e5" is numeric
// prints: "Not a number" is not numeric

==[[Perl]]==
[[Category:Perl]]

'''Interpreter:''' [[Perl]] 5.8

Quoting from [http://perldoc.perl.org/perlfaq4.html#How-do-I-determine-whether-a-scalar-is-a-number%2fwhole%2finteger%2ffloat%3f perlfaq4]:

''How do I determine whether a [[scalar]] is a number/whole/integer/float?''

Assuming that you don't care about [[IEEE]] notations like "NaN" or "Infinity", you probably just want to use a [[regular expression]].

if (/\D/) { print "has nondigits\n" }
if (/^\d+$/) { print "is a whole number\n" }
if (/^-?\d+$/) { print "is an integer\n" }
if (/^[+-]?\d+$/) { print "is a +/- integer\n" }
if (/^-?\d+\.?\d*$/) { print "is a real number\n" }
if (/^-?(?:\d+(?:\.\d*)?&\.\d+)$/) { print "is a decimal number\n" }
if (/^([+-]?)(?=\d&\.\d)\d*(\.\d*)?([Ee]([+-]?\d+))?$/)
{ print "a C float\n" }

There are also some commonly used modules for the task. [[Scalar::Util]] (distributed with 5.8) provides access to perl's internal function "looks_like_number" for determining whether a variable looks like a number. Data::Types exports functions that validate data types using both the above and other regular expressions. Thirdly, there is "Regexp::Common" which has regular expressions to match various types of numbers. Those three modules are available from the CPAN.

If you're on a [[POSIX]] system, Perl supports the "[[POSIX::strtod]]" function. Its semantics are somewhat cumbersome, so here's a "getnum" wrapper function for more convenient access. This function takes a string and returns the number it found, or "[[undef]]" for input that isn't a C float. The "is_numeric" function is a front end to "getnum" if you just want to say, ''Is this a float?''

sub getnum {
use POSIX qw(strtod);
my $str = shift;
$str =~ s/^\s+//;
$str =~ s/\s+$//;
$! = 0;
my($num, $unparsed) = strtod($str);
if (($str eq '') && ($unparsed != 0) && $!) {
return undef;
} else {
return $num;
}
}

sub is_numeric { defined getnum($_[0]) }

Or you could check out the String::Scanf module on the CPAN instead. The POSIX module (part of the standard Perl distribution) provides the "strtod" and "strtol" for converting strings to double and longs, respectively.

==[[PHP]]==
[[Category:PHP]]

<?php
$string = '123';
if(is_numeric($string)) {
}

==[[PL/SQL|PL/SQL]]==
[[Category:PL/SQL|PL/SQL]]

FUNCTION IsNumeric( value IN VARCHAR2 )
RETURN BOOLEAN
IS
help NUMBER;
BEGIN
help := to_number( value );
return( TRUE );
EXCEPTION
WHEN others THEN
return( FALSE );
END;

Value VARCHAR2( 10 ) := '123';
IF( IsNumeric( Value ) )
THEN
NULL;
END IF;

==[[Python]]==
[[Category:Python]]

s = '123'
try:
i = int(s)
# use i
except ValueError:
# s is not numeric

Or for positive integers:

s = '123'
if s.isdigit():
...

==[[Ruby]]==
[[Category:Ruby]]

value=123
if Numeric===value
...

==[[Scheme]]==
[[Category:Scheme]]

<tt>number?</tt> is a standard R5RS scheme predicate
(define is-numeric? number?)

==[[SQL]]==
[[Category:SQL]]
-- Tested on Microsoft SQL Server 2005
declare @s varchar(10)
set @s = '1234.56'
print isnumeric(@s) --prints 1 if numeric, 0 if not.
if isnumeric(@s)=1 begin print 'Numeric' end
else print 'Non-numeric'

==[[Tcl]]==
[[Category:Tcl]]

if { [string is double $varname] } then { ... }

Also <tt>string is integer</tt> (, <tt>string is alnum</tt> etc etc)

==[[Visual Basic .NET]]==
[[Category:Visual Basic .NET]]

Compiler: [[Visual Basic]] 2005
Dim Value As String = "123"
If IsNumeric(Value) Then
End If

==[[Toka]]==
[[Category:Toka]]

Returns TRUE (-1) if character-string parameter represents a signed
or unsigned integer. Otherwise returns FALSE (zero).

[ ( string -- flag )
>number nip ] is isNumeric

==[[VBScript]]==
[[Category:VBScript]]

IsNumeric(Expr)

Returns a True if numeric and a false if not.

Revision as of 15:41, 8 September 2007

patapam igrometro capello lettini fasciatoi riso bianco batteria nokia 9210 i offerta computer www alessio it divas immagini inedite per gran turismo 4 stampante epson stylus color donne mature anziane troie cubical quad onar o 347 ka tito puente lyrics atlantic city usa un trailer per battlefield command navman pocket pc uomo perfetto seneca hard disk con lettore compact flash isole vacanze pamukkale guem toner epson epl 5700 frigorifero da incasso monoporta love energy trolley 50 camping gear testi hit mania dance 2004 palermo coppie caricatore pioneer autoradio primier impacto http www publiweb porno gratis theme park world hi q gasca me diamond music ytunnel toner smaltimento hector y tito y noriega manziana sesso ingoio gratis polistirolo brindisi prole flipper telesystem bed platform tv lcd sony 1366x768 equinox jamie lee kurtis innsbruck alberghi e hotel sam group tutte le carte magic batteria npfr1 abbonamento periodico tvixm3000u 160gb utility video multimedia lavoro rivoli rober hatemo gurur sassofono blu corsa di macchine gas piccolo riscaldamento fabrizio de andre raccolta che tettone ufficio arredato bangkok intrattenimento tinto fermo posta last christmas degli wham tabulati musica rock lettore dvd divx roadstar banja nuove immagini e video per top spin just i can t wait until gara di graffiti gestione orari turnisti moore demi lampade di emergenza uscita dv videocamere mp3 radio fm nuova opel auto nuove renault 19 16v rosana diaz trucchi gt3 ps2 b m x mercedes ml nuove quart una fortuna da morire in campeggio a beverly hills come fare pompini toner konica 1120 bravo club it storia di question mark flash pen drive memory card biesiada bruciatori barbecue e accessori quanla promesse di marinaio radeon x850xt 256mb tipsy j kwon hitachi 160 gb sex10 super cazzone royal g galos immaggini d piscine copertina di resto in ascolto nettuno (astronomia) mixer 4 muro philips mikela calcetto a 5 femminile sex con ragazze che vanno a scuola panasonic kxtca151exm rodolfo gaitan castro sunny cruz custine adolphe giochi x box ballerine per feste private reminder frankee fuck back il settecento mama kin daniele prende il treno cersaie scheda grafica dual feltrinelli miglior prezzo cellulare nokia 6600 il soldato innammorato sette ore di guai raghav la rosa di jericho serenissima t f vs moltosugo mp3go per nokia 3650 margaret hassan morte unione provinciale artigiani di padova youre under arrest the movie ixus 400 ventole 80x80 motto mini foto pornostar famose bob x philips 3cd mp3 cardio on line srl una sposa per mao annuncio personali foto silenzio militare satanik www gdif it locandine film dvd gratis benassi bros i love my sex bianco con il giallo spartito secondo aggiornamento disponibile per ghost recon 2 feliz navidad thermaltake tr2 stufe in maiolica www netmeeting it leslie cheung buscopan finanziamento nuoro datteln hp batteria nx6110 dvdr 8x datawrite jeans calvin klein uomo ganoderma foto sfondi cavalli siliconi nuova tucson auto km 0 ballata in blu motoracer 2 caricabatterie sony pctv 200e bulloneria case vacanza capri stilografica tvc lcd 32 samsung ganguro girl o zone dragostea din tei remix version calendario flavio montrucchio funeral of heart bataille henry musique gratuite thomson mp3 20gb combattimenti dieta anti colesterolo senza tubo severina vukovic video www tintuc vn run dmc together forever greatest hits 1983 2000 nikon custodia subacquea r50e centrino epson color 1500 cartina stradale londra latte in polvere mellin sd io dvd recorder rh7500 traduttori danese eminflex dvd decrypter download vini friuli annuncio toscana carta credito bancaria ivy quins everybody s gotta learn sometimes beck

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