Empty string: Difference between revisions
→{{header|jq}}: assignment to a variable
(jq) |
(→{{header|jq}}: assignment to a variable) |
||
Line 558:
=={{header|jq}}==
jq strings are JSON strings. The empty string literal is simply <tt>""</tt>. It can be assigned to a variable as illustrated by this example:<lang jq>"" as $x </lang>If s is a string or an array, then the additive "zero" for s can be created by writing s[0:0]. That is, if s is a string, then s[0:0] will yield the empty string. This is useful when writing polymorphic functions.
To determine whether a string, s, is empty:<lang jq>s == ""
# or:
s|length == 0</lang>To determine whether a string, s, is non-empty:<lang jq>s != ""▼
▲To determine whether a string, s, is non-empty:<lang jq>s != ""
# or:
s.length != 0 # etc.</lang>
|