isStringScalar

Tests whether a value is a string array with exactly one element.

Category: Language Fundamentals > Data Types

Syntax

tf = isStringScalar(A)

Returns true if A is a 1-by-1 string array.

Description

The function is useful for validating arguments that must be one piece of text. A character vector gives false even though it is one text value, and so does a string array with several elements or none. A string holding missing still counts as a scalar string.

Input arguments

A
Any value.

Output arguments

tf
Logical scalar.

Example

One string or many

isStringScalar("hello")
isStringScalar('hello')
isStringScalar(["a" "b"])
isStringScalar(strings(0,1))
Output
ans = logical
   1
ans = logical
   0
ans = logical
   0
ans = logical
   0

See also

isstring ischar mustBeTextScalar string