How to resolve the algorithm Strip control codes and extended characters from a string step by step in the Nim 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 Nim 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 Nim programming language
Source code in the nim programming language
proc stripped(str: string): string =
result = ""
for c in str:
if ord(c) in 32..126:
result.add c
proc strippedControl(str: string): string =
result = ""
for c in str:
if ord(c) in {32..126, 128..255}:
result.add c
echo strippedControl "\ba\x00b\n\rc\fdÄ"
echo stripped "\ba\x00b\n\rc\fd\xc3"
You may also check:How to resolve the algorithm Maze generation step by step in the Ada programming language
You may also check:How to resolve the algorithm Binary search step by step in the PARI/GP programming language
You may also check:How to resolve the algorithm Achilles numbers step by step in the FreeBASIC programming language
You may also check:How to resolve the algorithm Go Fish step by step in the Python programming language
You may also check:How to resolve the algorithm Descending primes step by step in the Delphi programming language