isstring

Purpose

Returns a 1 if the input is a string or string array, otherwise 0.

Format

ret = isstring(x)
Parameters:

x (Matrix, dataframe, string or string array) – The symbol to be checked.

Returns:

ret (Scalar) – A 1 if the input is a string or string array, otherwise 0.

Examples

Basic cases

// Test for string
ret_1 = isstring("This is a string");

// Form string 'sa'
sa = "This is a " $| "string array";

// Test if sa is string
ret_2 = isstring(sa);

The code above assigns ret_1 and ret_2 to be equal to 1.

x = { 1 2, 3 4 };
ret_3 = isstring(x);

The code above assigns ret_3 to be equal to 0.

Dataframes

As we would expect, the isstring() will return a 1 when passed the following string array.

// Create string array
sa = "high" $| "medium" $| "high" $| "low";

// Test if sa is a string
ret = isstring(sa);
ret = 1

However, if we convert it to a categorical or string dataframe isstring() will return a 0.

// Create string array
sa = "high" $| "medium" $| "high" $| "low";

// Create a dataframe from the string data
df = asdf(sa, "Fan speed");
print df;
Fan speed
     high
   medium
     high
      low
ret = isstring(df);

After the above code ret will equal 0.

Remarks

  1. To find out if a dataframe or dataframe column is of type string, category, date or number, use getcoltypes().

See also

Functions getcoltypes(), type()