How to resolve the algorithm Strip control codes and extended characters from a string step by step in the BASIC 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 BASIC 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 BASIC programming language

Source code in the basic programming language

DECLARE FUNCTION strip$ (what AS STRING)
DECLARE FUNCTION strip2$ (what AS STRING)

DIM x AS STRING, y AS STRING, z AS STRING

'   tab                c+cedilla           eof
x = CHR$(9) + "Fran" + CHR$(135) + "ais" + CHR$(26)
y = strip(x)
z = strip2(x)

PRINT "x:"; x
PRINT "y:"; y
PRINT "z:"; z

FUNCTION strip$ (what AS STRING)
    DIM outP AS STRING, L0 AS INTEGER, tmp AS STRING
    FOR L0 = 1 TO LEN(what)
        tmp = MID$(what, L0, 1)
        SELECT CASE ASC(tmp)
            CASE 32 TO 126
                outP = outP + tmp
        END SELECT
    NEXT
    strip$ = outP
END FUNCTION

FUNCTION strip2$ (what AS STRING)
    DIM outP AS STRING, L1 AS INTEGER, tmp AS STRING
    FOR L1 = 1 TO LEN(what)
        tmp = MID$(what, L1, 1)
        SELECT CASE ASC(tmp)
                'normal     accented    various     greek, math, etc.
            CASE 32 TO 126, 128 TO 168, 171 TO 175, 224 TO 253
                outP = outP + tmp
        END SELECT
    NEXT
    strip2$ = outP
END FUNCTION


  

You may also check:How to resolve the algorithm Parallel brute force step by step in the PureBasic programming language
You may also check:How to resolve the algorithm Chinese remainder theorem step by step in the VBA programming language
You may also check:How to resolve the algorithm Exceptions step by step in the Logtalk programming language
You may also check:How to resolve the algorithm Bitmap/PPM conversion through a pipe step by step in the Raku programming language
You may also check:How to resolve the algorithm Bitmap/Midpoint circle algorithm step by step in the Perl programming language