The task doesn't define which strings are considered "numeric", so we do Integers and Doubles, which should catch the most common cases (including hexadecimal 0x notation): so read s:: Int (for instance) could be reliably used if string s passed these tests. The Lab VIEW version is shown on the top-right hand corner.

Haxe has a built-in function that will convert a string to an integer, so we can use that to determine if the string is numeric or not. You can download it, then drag-and-drop it onto the Lab VIEW block diagram from a file browser, and it will appear as runnable, editable code.

"is" : "is not" println(@sprintf(" 5s %s a direct numeric literal.", t, fl))end 1 is a direct numeric literal. Digit(c)) return false end end trueend puts '123 is numeric' if is_numeric2? ('1.2.3') # use a regular expression def is_numeric3? The scan Float method will return YES if the string is numeric, even if the number is actually too long to be contained by the precision of a float.

If we want to scan by hand, we could use a function like the following, that checks if a number is an integer positive or negative number; spaces can appear at the beginning, but not after the number, and the ' ' or '-' can appear only attached to the number (" 123" returns YES, but " 123" returns NO).

' is NOT a number '0' is a number '0.0' is a number '.123' is a number '-.123' is a number '12E3' is a number '12E-3' is a number '12 3' is NOT a number 'end' is NOT a number0:? This function is not particularly useful in a statically typed language.

Instead, one would just attempt to convert the string to the desired type with read or reads, and handle parsing failure appropriately. This image is a VI Snippet, an executable image of Lab VIEW code.

This function is not particularly useful in a statically typed language.

Math Works does not warrant, and disclaims all liability for, the accuracy, suitability, or fitness for purpose of the translation.

Returns true if it does, false otherwise % logical procedure is Numeric( string(32) value text ) ; begin logical ok; % the "number" cannot be blank % ok := ( text not = " " ); if ok then begin % there is at least one non-blank character % % must have either an integer or real/immaginary number % % integer: [ |-]digit-sequence % % real: [ |-][digit-sequence].digit-sequence['integer][L] % % or: [ |-]digit-sequence[.[digit-sequence'integer[L] % % imaginary: % % [ |-][digit-sequence].digit-sequence['integer][L]I% % or: [ |-]digit-sequence[.[digit-sequence]]'integer[L]I% % The "I" at the end of an imaginary number can appear % % before or after the "L" (which indicates a long number) % % the "I" and "L" can be in either case % procedure next Char ; char Pos := char Pos 1; logical procedure have( string(1) value ch ) ; ( char Pos 0 and text(max Char//1) = " " do max Char := max Char - 1; % skip leading spacesx % while have( " " ) do next Char; % skip optional sign % if have( " " ) or have( "-" ) then next Char; if have Digit then begin % have a digit sequence % had Digits := true; while have Digit do next Char end if_have_sign ; if have( "." ) then begin % real or imaginary number % next Char; is Real := true; had Digits := had Digits or have Digit; while have Digit do next Char end if_have_point ; % should have had some digits % ok := had Digits; if ok and have( "'" ) then begin % the number has an exponent % is Real := true; next Char; % skip optional sign % if have( " " ) or have( "-" ) then next Char; % must have a digit sequence % ok := have Digit; while have Digit do next Char; end if_ok_and_have_exponent ; % if it is a real number, there could be L/I suffixes % if ok and is Real then begin integer LCount, ICount; LCount := 0; ICount := 0; while have( "L" ) or have( "l" ) or have( "I" ) or have( "i" ) do begin if have( "L" ) or have( "l" ) then LCount := LCount 1 else ICount := ICount 1; next Char end while_have_L_or_I ; % there can be at most one L and at most 1 I % ok := ( LCount = max Char end if_ok ; ok end is Numeric ; % test the is Numeric procedure % procedure test Is Numeric( string(32) value n ; logical value expected Result ) ; begin logical actual Result; actual Result := is Numeric( n ); write( s_w := 0 , """", n, """ is " , if actual Result then "" else "not " , "numeric " , if actual Result = expected Result then "" else " NOT " , "as expected" ) end test Is Numeric ; test Is Numeric( "", false ); test Is Numeric( "b", false ); test Is Numeric( ".", false ); test Is Numeric( ".'3", false ); test Is Numeric( "3.'", false ); test Is Numeric( "0.0z44", false ); test Is Numeric( "-1IL", false ); test Is Numeric( "4.5'23ILL", false ); write( "---------" ); test Is Numeric( "-1", true ); test Is Numeric( " .345", true ); test Is Numeric( "4.5'23I", true ); test Is Numeric( "-5' 3i", true ); test Is Numeric( "-5'-3l", true ); test Is Numeric( " -.345LI", true ); end." " is not numeric as expected "b " is not numeric as expected ". The 'false' tells each method to return null if the string does not parse as a number of given type, otherwise, the 'from Str' method throws an exception. as double = 1234s" 1234e" is-numeric \ 1234e as float = 1234.s" $1234" is-numeric \ $1234 as integer = 4660 ( hex literal )s" 10" is-numeric \ 10 as integer = 10 ( binary literal )s" beef" is-numeric \ beef isn't numeric in base 10hexs" beef" is-numeric \ beef as integer = BEEFs" &1234" is-numeric \ &1234 as integer = 4D2 ( decimal literal ) Free BASIC has a built-in Val() function which converts numeric strings to doubles.

" is not numeric as expected ".'3 " is not numeric as expected "3.' " is not numeric as expected "0.0z44 " is not numeric as expected "-1IL " is not numeric as expected "4.5'23ILL " is not numeric as expected --------- "-1 " is numeric as expected " .345 " is numeric as expected "4.5'23I " is numeric as expected "-5' 3i " is numeric as expected "-5'-3l " is numeric as expected " -.345LI " is numeric as expected String numeric String = '123456'; String partly Numeric String = '123DMS'; String decimal String = '123.456'; System.debug(numeric Numeric()); // this will be true System.debug(partly Numeric Numeric()); // this will be false System.debug(decimal Numeric()); // this will be false System.debug(decimal String.remove('.')Numeric()); // this will be true Auto Hotkey has no explicitly defined variable types. cc -c c cc -o isnumber o -lbacon -lm Done, program 'isnumber' ready. However, it is not ideal for the present task since it will try to convert as much of the string as it can (so "123xyz" would convert to 123) and return 0 if a conversion on this basis is not possible (i.e. I've therefore written a custom function which recognizes signed numbers in bases from 2 to 16 (but only integral numbers for bases other than 10).

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.

||Math Works does not warrant, and disclaims all liability for, the accuracy, suitability, or fitness for purpose of the translation.Returns true if it does, false otherwise % logical procedure is Numeric( string(32) value text ) ; begin logical ok; % the "number" cannot be blank % ok := ( text not = " " ); if ok then begin % there is at least one non-blank character % % must have either an integer or real/immaginary number % % integer: [ |-]digit-sequence % % real: [ |-][digit-sequence].digit-sequence['integer][L] % % or: [ |-]digit-sequence[.[digit-sequence]]'integer[L] % % imaginary: % % [ |-][digit-sequence].digit-sequence['integer][L]I% % or: [ |-]digit-sequence[.[digit-sequence]]'integer[L]I% % The "I" at the end of an imaginary number can appear % % before or after the "L" (which indicates a long number) % % the "I" and "L" can be in either case % procedure next Char ; char Pos := char Pos 1; logical procedure have( string(1) value ch ) ; ( char Pos 0 and text(max Char//1) = " " do max Char := max Char - 1; % skip leading spacesx % while have( " " ) do next Char; % skip optional sign % if have( " " ) or have( "-" ) then next Char; if have Digit then begin % have a digit sequence % had Digits := true; while have Digit do next Char end if_have_sign ; if have( "." ) then begin % real or imaginary number % next Char; is Real := true; had Digits := had Digits or have Digit; while have Digit do next Char end if_have_point ; % should have had some digits % ok := had Digits; if ok and have( "'" ) then begin % the number has an exponent % is Real := true; next Char; % skip optional sign % if have( " " ) or have( "-" ) then next Char; % must have a digit sequence % ok := have Digit; while have Digit do next Char; end if_ok_and_have_exponent ; % if it is a real number, there could be L/I suffixes % if ok and is Real then begin integer LCount, ICount; LCount := 0; ICount := 0; while have( "L" ) or have( "l" ) or have( "I" ) or have( "i" ) do begin if have( "L" ) or have( "l" ) then LCount := LCount 1 else ICount := ICount 1; next Char end while_have_L_or_I ; % there can be at most one L and at most 1 I % ok := ( LCount = max Char end if_ok ; ok end is Numeric ; % test the is Numeric procedure % procedure test Is Numeric( string(32) value n ; logical value expected Result ) ; begin logical actual Result; actual Result := is Numeric( n ); write( s_w := 0 , """", n, """ is " , if actual Result then "" else "not " , "numeric " , if actual Result = expected Result then "" else " NOT " , "as expected" ) end test Is Numeric ; test Is Numeric( "", false ); test Is Numeric( "b", false ); test Is Numeric( ".", false ); test Is Numeric( ".'3", false ); test Is Numeric( "3.'", false ); test Is Numeric( "0.0z44", false ); test Is Numeric( "-1IL", false ); test Is Numeric( "4.5'23ILL", false ); write( "---------" ); test Is Numeric( "-1", true ); test Is Numeric( " .345", true ); test Is Numeric( "4.5'23I", true ); test Is Numeric( "-5' 3i", true ); test Is Numeric( "-5'-3l", true ); test Is Numeric( " -.345LI", true ); end." " is not numeric as expected "b " is not numeric as expected ". The 'false' tells each method to return null if the string does not parse as a number of given type, otherwise, the 'from Str' method throws an exception. as double = 1234s" 1234e" is-numeric \ 1234e as float = 1234.s" $1234" is-numeric \ $1234 as integer = 4660 ( hex literal )s" 10" is-numeric \ 10 as integer = 10 ( binary literal )s" beef" is-numeric \ beef isn't numeric in base 10hexs" beef" is-numeric \ beef as integer = BEEFs" &1234" is-numeric \ &1234 as integer = 4D2 ( decimal literal ) Free BASIC has a built-in Val() function which converts numeric strings to doubles." is not numeric as expected ".'3 " is not numeric as expected "3.' " is not numeric as expected "0.0z44 " is not numeric as expected "-1IL " is not numeric as expected "4.5'23ILL " is not numeric as expected --------- "-1 " is numeric as expected " .345 " is numeric as expected "4.5'23I " is numeric as expected "-5' 3i " is numeric as expected "-5'-3l " is numeric as expected " -.345LI " is numeric as expected String numeric String = '123456'; String partly Numeric String = '123DMS'; String decimal String = '123.456'; System.debug(numeric Numeric()); // this will be true System.debug(partly Numeric Numeric()); // this will be false System.debug(decimal Numeric()); // this will be false System.debug(decimal String.remove('.')Numeric()); // this will be true Auto Hotkey has no explicitly defined variable types. cc -c c cc -o isnumber o -lbacon -lm Done, program 'isnumber' ready. However, it is not ideal for the present task since it will try to convert as much of the string as it can (so "123xyz" would convert to 123) and return 0 if a conversion on this basis is not possible (i.e. I've therefore written a custom function which recognizes signed numbers in bases from 2 to 16 (but only integral numbers for bases other than 10).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.A far better validator can be found on Stack Overflow[1] , that evaluate to numbers as well as certain elaborate numbers (large integers, rationals and complex numbers) whose literals parse to expressions that must be evaluated to yield numbers. (s: string) if (s == nil || Empty()) return false end if (! ('abc')puts '123- is not numeric' unless is_numeric2? If there a string of digits followed by an "e" or an "E" followed in turn by more digits, the numbers after the letter are treated as an exponent.

]]Aug