How to resolve the algorithm Split a character string based on change of character step by step in the Transd 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 Transd 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 Transd programming language

Source code in the transd programming language

#lang transd

MainModule: {
    s: "gHHH5YY++///\\",
    _start: (λ
        (with res ""
            (for c in (split s "") do
                (if (neq Char(c) (back res)) (+= res ", "))
                (+= res c))
            (textout res))

        (lout "Second variant: ")

        (for v in (values (group-by (split s ""))) do
            (textout (if @idx ", ") (join v "")))
    )
}


  

You may also check:How to resolve the algorithm N'th step by step in the Clojure programming language
You may also check:How to resolve the algorithm Polynomial regression step by step in the J programming language
You may also check:How to resolve the algorithm Even or odd step by step in the Raku programming language
You may also check:How to resolve the algorithm Random number generator (included) step by step in the Déjà Vu programming language
You may also check:How to resolve the algorithm Sorting algorithms/Permutation sort step by step in the ARM Assembly programming language