String comparison: Difference between revisions

(FutureBasic solution added)
Line 2,504:
 
=={{header|jq}}==
jq strings are JSON strings. The jq comparison operators (==, !=, <, <=, >=, >) can be used to compare strings or indeed any JSON entities. Similarly, jq's <tt>sort</tt> and <tt>unique</tt> filters can be used to sort strings. The ordering of strings is determined by the Unicode codepoints.
 
<syntaxhighlight lang="jq"># Comparing two strings for exact equality:
Line 2,517:
 
# > is the inverse of < </syntaxhighlight>
jq provides `ascii_downcase` and `ascii_upcase` for ASCII case conversion.
Currently, jq does not have any "toupper" or "tolower" case conversion, but it is easy to define jq equivalents of ruby's downcase and upcase:<syntaxhighlight lang="jq">
# Only characters A to Z are affected
def downcase:
explode | map( if 65 <= . and . <= 90 then . + 32 else . end) | implode;
 
# Only characters a to z are affected
def upcase:
explode | map( if 97 <= . and . <= 122 then . - 32 else . end) | implode;</syntaxhighlight>
With the caveat that these are what they are, case-insensitive comparisons can be achieved as illustrated by this example:
<syntaxhighlight lang="jq">("AtoZ" | upcaseascii_upcase) == ("atoz" | upcaseascii_upcase) # true</syntaxhighlight>
Numeric strings are treated as any other JSON strings.
 
jq has an extensive library of built-in functions for handling strings. The most recent versions of jq (since 1.4) also have extensive support for PCRE regular expressions (regex), including named captures. Pleaseand seean [http://stedolan.github.io/jq/manual/#Builtinoperatorsandfunctions|jqoption Builtinto Operatorsturn andcase-sensitivity Functions]off. for details.
Please see [http://stedolan.github.io/jq/manual/#Builtinoperatorsandfunctions|jq Builtin Operators and Functions] for details.
 
=={{header|Julia}}==
2,442

edits