StringLength¶
Status: Stable
documented, exercised by the test suite and/or worked examples, with no known limitations recorded.
Description¶
Examples¶
All examples below are verified against the current Mathilda build.
In[1]:= StringLength["tiger"]
Out[1]= 5
In[2]:= StringLength[""]
Out[2]= 0
In[3]:= StringLength["hello world"]
Out[3]= 11
In[4]:= StringLength[x]
Out[4]= StringLength[x]
Implementation notes¶
builtin_stringlength checks for a single EXPR_STRING argument and returns expr_new_integer((int64_t)strlen(arg->data.string)) — a byte count, not a codepoint count. Non-string arguments leave the call unevaluated (NULL). ATTR_LISTABLE | ATTR_PROTECTED, so it threads element-wise over a list of strings automatically.
Attributes: Listable, Protected.
Implementation status¶
Stable — documented, exercised by the test suite and/or worked examples, with no known limitations recorded.
References¶
- Source:
src/picostrings.c - Specification:
docs/spec/builtins/string-operations.md
Notes & additional examples¶
Worked examples¶
In[1]:= StringLength["hello"]
Out[1]= 5
In[2]:= StringLength["Mathilda"]
Out[2]= 8
In[3]:= StringLength[""]
Out[3]= 0
Notes¶
StringLength returns the number of characters in a string; the empty string has length 0.