NCL Website header
NCL Home > Documentation > Functions > Unclassified routines

str_match_bool

Returns a logical array of True/False/Missing indicating where the input array of strings contain the given substring (case sensitive).

Available in version 6.5.0 and later.

Prototype

	function str_match_bool (
		string_array [*] : string,  
		sub_string   [1] : string   
	)

	return_val [dimsizes(string_array)] :  logical

Arguments

string_array

A string array of any dimensionality.

sub_string

The substring to be matched.

Description

This function returns a logical array the same size as the input string_array that is set to True for every element that contains sub_string, the logical "Missing" for every value that is missing in the string_array, and False otherwise.

str_match_bool is case SENSITIVE. Use str_match_bool_ic if you need case insensitivity.

Jared Lee (NCAR/RAL) contributed the original version of this function.

See Also

str_match_bool_ic, str_index_of_substr, str_sub_str, str_match, str_match_ic, str_match_ind, str_match_ind_ic, str_match_regex, str_match_ic_regex, str_match_ind_regex, str_match_ind_ic_regex

Examples

Example 1

  s = (/ "foo", "bar", "missing", "Foo", "FOOBAR", "barfoo", "oof" /)
  s@_FillValue = "missing"

  smb = str_match_bool(s, "foo")
  print(smb)
Output:

   Variable: smb
   Type: logical
   Total Size: 28 bytes
               7 values
   Number of Dimensions: 1
   Dimensions and sizes:[7]
   Coordinates: 
   Number Of Attributes: 1
   _FillValue :Missing

   True
   False
   Missing
   False
   False
   True
   False

Example 2

If you need the return array to be False at locations where the input strings are missing (instead of the logical "Missing"), then use the following:

  smb = str_match_bool(s, "foo")
  smb = where(ismissing(smb), False, smb)
  print(smb)
Output:

   Variable: smb
   Type: logical
   Total Size: 28 bytes
               7 values
   Number of Dimensions: 1
   Dimensions and sizes:[7]
   Coordinates: 
   Number Of Attributes: 1
   _FillValue :Missing

   True
   False
   False
   False
   False
   True
   False