NCL Home > Documentation > Functions > Variable query, String manipulation


Returns True for every element of the input string array that contains a numeric value.

Available in version 6.4.0 and later.


	function is_string_numeric (
		arg  : string   

	return_val [dimsizes(arg)] :  logical



A string array of any dimensionality.


This function returns True for every element of the input string array that contains a numeric value, False for every string that is not numeric or missing, and missing for every string that is equal to missing. A string is considered a numeric value if it consists of any combination of numbers 0 through 9, or the characters "e" or "E":

  • "1"
  • "-100"
  • "1e10"
  • "3.14159"
  • "-1E20"

None of NCL's literal types will be seen as numeric by this function. This is intentional. Hence, the following strings would not be considered to be numeric:

  • "2h"
  • "123l"
  • "123.456d"

If any of the input strings is missing, then the default missing value for a logical will be returned for that value.

See Also

Logical functions:
isbyte, ischar, isdouble, isenumeric, isfloat, isint, isint64, isinteger, islong, isnumeric, isshort, issnumeric, isubyte, isuint, isuint64, isulong, isushort, isunsigned

Conversion functions:
tobyte, tochar, todouble, tofloat, toint, toint64, tointeger, tolong, toshort, tosigned, tostring, toubyte, touint, touint64, toulong, tounsigned, toushort

Other useful functions:
typeof, sizeof, ismissing, default_fillvalue, set_default_fillvalue


Example 1

This example should return an array of all True values:

  s1 = (/"-5","1","-1e20","2.8","1e30"/)
  print("Is " + s1 + " numeric? " + is_string_numeric(s1))


  (0)   Is -5 numeric? True
  (1)   Is 1 numeric? True
  (2)   Is -1e20 numeric? True
  (3)   Is 2.8 numeric? True
  (4)   Is 1e30 numeric? True
Example 2

Strings containing NCL literal values will not be seen as numeric by this function:

  x  = 123.456d
  sx = "123.456d"
  print(isnumeric((x))             ; True
  print(is_string_numeric((sx))    ; False

  l  = 123l
  sl = "123l"
  print(isnumeric((l))             ; True
  print(is_string_numeric((sl))    ; False

Example 3

If a string array contains missing values, even if the missing values are valid numbers, this function will still return missing:

  s2 = (/"1e9","one","999","1.3d","500l","-100","-1e10", "0","999","10Z","ABC123"/)
  s2@_FillValue = "999"

  print("Is " + s2 + " numeric? " + is_string_numeric(s2))


  (0)    Is 1e9 numeric? True
  (1)    Is one numeric? False
  (2)    Is 999 numeric? Missing         <== "999" was marked as a missing value
  (3)    Is 1.3d numeric? False
  (4)    Is 500l numeric? False
  (5)    Is -100 numeric? True
  (6)    Is -1e10 numeric? True
  (7)    Is 0 numeric? True
  (8)    Is 999 numeric? Missing
  (9)    Is 10Z numeric? False
  (10)   Is ABC123 numeric? False