How to resolve the algorithm String case step by step in the jq programming language
Published on 12 May 2024 09:40 PM
How to resolve the algorithm String case step by step in the jq programming language
Table of Contents
Problem Statement
Take the string alphaBETA and demonstrate how to convert it to:
Use the default encoding of a string literal or plain ASCII if there is no string literal in your language. Note: In some languages alphabets toLower and toUpper is not reversable. Show any additional case conversion functions (e.g. swapping case, capitalizing the first letter, etc.) that may be included in the library of your language.
Let's start with the solution:
Step by Step solution about How to resolve the algorithm String case step by step in the jq programming language
Source code in the jq programming language
# like ruby's downcase - only characters A to Z are affected
def ascii_downcase:
explode | map( if 65 <= . and . <= 90 then . + 32 else . end) | implode;
# like ruby's upcase - only characters a to z are affected
def ascii_upcase:
explode | map( if 97 <= . and . <= 122 then . - 32 else . end) | implode;
"alphaBETA" | ascii_upcase
#=> "ALPHABETA"
"alphaBETA" | ascii_downcase
#=> "alphabeta"
jq -n '"á" | test("Á";"i")' # case-insensitive search
#=> true
You may also check:How to resolve the algorithm Comments step by step in the Forth programming language
You may also check:How to resolve the algorithm Towers of Hanoi step by step in the Prolog programming language
You may also check:How to resolve the algorithm Abundant odd numbers step by step in the Common Lisp programming language
You may also check:How to resolve the algorithm Prime conspiracy step by step in the Picat programming language
You may also check:How to resolve the algorithm Program name step by step in the D programming language