String append: Difference between revisions

Content added Content deleted
(jq)
(jq (header))
Line 198: Line 198:
"Goodbye, World!"
"Goodbye, World!"
</pre>
</pre>
=={{header|jq}}==

jq's <code>+</code> operator can be used to append two strings, and under certain circumstances the <code>+=</code> operator can be used as an abbreviation for appending a string to an existing string. For example, all three of the following produce the same output:<lang jq>"Hello" | . += ", world!"
jq's <code>+</code> operator can be used to append two strings, and under certain circumstances the <code>+=</code> operator can be used as an abbreviation for appending a string to an existing string. For example, all three of the following produce the same output:<lang jq>"Hello" | . += ", world!"


Line 204: Line 204:


{ "greeting": "Hello"} | .greeting += ", world!" | .greeting</lang>
{ "greeting": "Hello"} | .greeting += ", world!" | .greeting</lang>
However the <code>+=</code> operator cannot be used with jq variables in the conventional manner. One could however use the technique illustrated by the following:<lang jq>"Hello" as $a | $a | . += ", world!" as $a | $a</lang>
However the <code>+=</code> operator cannot be used with jq variables in the conventional manner. One could nevertheless use the technique illustrated by the following:<lang jq>"Hello" as $a | $a | . += ", world!" as $a | $a</lang>


=={{header|Julia}}==
=={{header|Julia}}==