Empty string: Difference between revisions

Content added Content deleted
(→‎{{header|jq}}: contrast JSON strings with jq interpolation directives)
Line 1,645: Line 1,645:


=={{header|jq}}==
=={{header|jq}}==
jq programs can read JSON strings as data and may contain JSON strings. This entry is focused on such strings and excludes from consideration interpolation directives, which have the form of strings but are not themselves valid JSON strings.
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:<syntaxhighlight lang="jq">"" as $x </syntaxhighlight>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.

The empty string literal is simply <tt>""</tt>. It can be assigned to a variable as illustrated by this example:<syntaxhighlight lang="jq">"" as $x </syntaxhighlight>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:<syntaxhighlight lang="jq">s == ""
To determine whether a string, s, is empty:<syntaxhighlight lang="jq">s == ""