How to resolve the algorithm String case step by step in the Modula-3 programming language

Published on 12 May 2024 09:40 PM

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

Source code in the modula-3 programming language

MODULE TextCase EXPORTS Main;

IMPORT IO, Text, ASCII;

PROCEDURE Upper(txt: TEXT): TEXT =
  VAR
    len := Text.Length(txt);
    res := "";
  BEGIN
    FOR i := 0 TO len - 1 DO
      res := Text.Cat(res, Text.FromChar(ASCII.Upper[Text.GetChar(txt, i)]));
    END;
    RETURN res;
  END Upper;

PROCEDURE Lower(txt: TEXT): TEXT =
  VAR
    len := Text.Length(txt);
    res := "";
  BEGIN
    FOR i := 0 TO len - 1 DO
      res := Text.Cat(res, Text.FromChar(ASCII.Lower[Text.GetChar(txt, i)]));
    END;
    RETURN res;
  END Lower;

BEGIN
  IO.Put(Upper("alphaBETA\n"));
  IO.Put(Lower("alphaBETA\n"));
END TextCase.

  

You may also check:How to resolve the algorithm Leap year step by step in the Ruby programming language
You may also check:How to resolve the algorithm Eban numbers step by step in the EasyLang programming language
You may also check:How to resolve the algorithm Arrays step by step in the AWK programming language
You may also check:How to resolve the algorithm Arithmetic/Integer step by step in the 11l programming language
You may also check:How to resolve the algorithm Fraction reduction step by step in the Pascal programming language