How to resolve the algorithm Split a character string based on change of character step by step in the Cowgol programming language

Published on 12 May 2024 09:40 PM

How to resolve the algorithm Split a character string based on change of character step by step in the Cowgol programming language

Table of Contents

Problem Statement

Split a (character) string into comma (plus a blank) delimited strings based on a change of character   (left to right). Show the output here   (use the 1st example below).

Blanks should be treated as any other character   (except they are problematic to display clearly).   The same applies to commas.

For instance, the string: should be split and show:

Let's start with the solution:

Step by Step solution about How to resolve the algorithm Split a character string based on change of character step by step in the Cowgol programming language

Source code in the cowgol programming language

include "cowgol.coh";

sub split(in: [uint8], buf: [uint8]): (out: [uint8]) is
    out := buf;
    loop
        [buf] := [in];
        if [in] == 0 then break; end if;
        if [in] != [@next in] and [@next in] != 0 then
            [buf+1] := ',';
            [buf+2] := ' ';
            buf := buf+2;
        end if;
        buf := buf+1;
        in := in+1;
    end loop;
end sub;

var buf: uint8[32];

print(split("gHHH5YY++//\\", &buf[0]));
print_nl();

  

You may also check:How to resolve the algorithm Y combinator step by step in the Vim Script programming language
You may also check:How to resolve the algorithm Find limit of recursion step by step in the Oz programming language
You may also check:How to resolve the algorithm Hello world/Text step by step in the OpenLisp programming language
You may also check:How to resolve the algorithm Array concatenation step by step in the Elena programming language
You may also check:How to resolve the algorithm Unprimeable numbers step by step in the Factor programming language