How to resolve the algorithm String case step by step in the Potion programming language

Published on 12 May 2024 09:40 PM

How to resolve the algorithm String case step by step in the Potion 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 Potion programming language

Source code in the potion programming language

lowercase = (str) :
   low = ("")
   str length times (i) :
      low append(if (65 <= str(i) ord and str(i) ord <= 90) :
         "abcdefghijklmnopqrstuvwxyz"(str(i) ord - 65)
      . else :
         str(i)
      .)
   .
   low join("")
.
uppercase = (str) :
   upp = ("")
   str length times (i) :
      upp append(if (97 <= str(i) ord and str(i) ord <= 122) :
         "ABCDEFGHIJKLMNOPQRSTUVWXYZ"(str(i) ord - 97)
      . else :
         str(i)
      .)
   .
   upp join("")
.

lowercase("alphaBETA") print
uppercase("alphaBETA") print

  

You may also check:How to resolve the algorithm The Twelve Days of Christmas step by step in the Python programming language
You may also check:How to resolve the algorithm Abundant, deficient and perfect number classifications step by step in the Go programming language
You may also check:How to resolve the algorithm 99 bottles of beer step by step in the FOCAL programming language
You may also check:How to resolve the algorithm Cholesky decomposition step by step in the BBC BASIC programming language
You may also check:How to resolve the algorithm Display an outline as a nested table step by step in the Mathematica / Wolfram Language programming language