How to resolve the algorithm Strip control codes and extended characters from a string step by step in the Action! programming language

Published on 12 May 2024 09:40 PM

How to resolve the algorithm Strip control codes and extended characters from a string step by step in the Action! programming language

Table of Contents

Problem Statement

Strip control codes and extended characters from a string.

The solution should demonstrate how to achieve each of the following results:

In ASCII, the control codes have decimal codes 0 through to 31 and 127. On an ASCII based system, if the control codes are stripped, the resultant string would have all of its characters within the range of 32 to 126 decimal on the ASCII table. On a non-ASCII based system, we consider characters that do not have a corresponding glyph on the ASCII table (within the ASCII range of 32 to 126 decimal) to be an extended character for the purpose of this task.

Let's start with the solution:

Step by Step solution about How to resolve the algorithm Strip control codes and extended characters from a string step by step in the Action! programming language

Source code in the action! programming language

BYTE FUNC IsAscii(CHAR c)
  IF c<32 OR c>124 OR c=96 OR c=123 THEN
    RETURN (0)
  FI
RETURN (1)

PROC Strip(CHAR ARRAY src,dst)
  CHAR c
  BYTE i

  dst(0)=0
  FOR i=1 TO src(0)
  DO
    c=src(i)
    IF IsAscii(c) THEN
      dst(0)==+1
      dst(dst(0))=c
    FI
  OD
RETURN

PROC Main()
  CHAR ARRAY
    src(20)=[16 0 16 96 123 'a 'b 'c 131 27 30 '1 '2 '3 4 1 20],
    dst(20)

  PrintF("Original string: ""%S""%E",src)
  Strip(src,dst)
  PrintF("Stripped string: ""%S""%E",dst)
RETURN

  

You may also check:How to resolve the algorithm Abbreviations, easy step by step in the Picat programming language
You may also check:How to resolve the algorithm Algebraic data types step by step in the Picat programming language
You may also check:How to resolve the algorithm Musical scale step by step in the Nanoquery programming language
You may also check:How to resolve the algorithm Haversine formula step by step in the ALGOL W programming language
You may also check:How to resolve the algorithm Best shuffle step by step in the Pascal programming language