StringQ¶
Status: Stable
documented, exercised by the test suite and/or worked examples, with no known limitations recorded.
Description¶
StringQ[expr]
gives True if expr is a string, and False otherwise. The empty
Notes
string "" gives True. Called with any number of arguments other than one it leaves the expression unevaluated (StringQ::argx).Examples (17)¶
Every input below was run against the current Mathilda build and its output recorded.
Basic examples (4)¶
In[1]:= StringQ["AbC"]
Out[1]= True
In[2]:= StringQ[""]
Out[2]= True
In[3]:= StringQ[123]
Out[3]= False
In[4]:= StringQ[] StringQ::argx: StringQ called with 0 arguments; 1 argument is expected.
Scope (6)¶
Overflows to +inf
MPFR, not machine
Exact Gaussian integer
Applications (7)¶
A string
The empty string still counts
A number is not a string
Not Listable: a list is not a string
Map it for an element-wise test
As a predicate
ToString always returns a String
Implementation notes¶
Algorithm. builtin_stringq (src/core.c) is a one-argument type test: it
returns True exactly when res->data.function.args[0]->type == EXPR_STRING, and
False for every other leaf or compound. The empty string "" is still an
EXPR_STRING, so it gives True. StringQ is not Listable, so a list of
strings is tested as a single object (a List is not a string) and gives False
rather than threading.
Data structures. A single tag check on the argument Expr; nothing is
allocated on the common path beyond the True/False symbol returned.
Complexity / limits. O(1). Any arity other than one is a malformed call
shape: the builtin routes a StringQ::argx diagnostic through
builtin_arg_error (so Quiet[]/Check[] see it) and leaves the call
unevaluated. Attributes Protected.
Attributes: Protected.
References¶
See also: AtomQ, NumberQ, IntegerQ, MachineNumberQ, Complex, ExactNumberQ
- Source:
src/core.c - Specification:
docs/spec/builtins/expression-information.md - Tests:
tests/test_core.c - Tests:
tests/test_graphics.c - Tests:
tests/test_ml_classify.c - Tests:
tests/test_pred_compile.c
Notes & additional examples¶
Notes¶
StringQ[expr]isTrueexactly whenexpris a string, including"", andFalsefor everything else. The test is a single type-tag check.- It is deliberately not
Listable, so a list is tested as a single object. Map it for an element-wise answer. - Any arity other than one emits
StringQ::argxthrough the message funnel and leaves the call unevaluated.Protected. - See also:
StringMatchQ,NumberQ,MatchQwith_String.