Empty string: Difference between revisions
Content added Content deleted
(jq) |
(→{{header|jq}}: assignment to a variable) |
||
Line 558: | Line 558: | ||
=={{header|jq}}== |
=={{header|jq}}== |
||
jq strings are JSON strings. The empty string literal is simply <tt>""</tt>. |
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. |
||
If s is a string or an array, then the additive "zero" for s can be created as 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 == "" |
To determine whether a string, s, is empty:<lang jq>s == "" |
||
# or: |
# or: |
||
⚫ | |||
s|length == 0 |
|||
</lang> |
|||
⚫ | |||
# or: |
# or: |
||
s.length != 0 # etc.</lang> |
s.length != 0 # etc.</lang> |