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

Source code in the dyalect programming language

func String.SmartSplit() {
    var c
    var str = ""
    var last = this.Length() - 1
 
    for n in 0..last {
        if c && this[n] != c {
            str += ", "
        }
        c = this[n]
        str += c
    }
 
    str
}
 
print("gHHH5YY++///\\".SmartSplit())

  

You may also check:How to resolve the algorithm Filter step by step in the VBA programming language
You may also check:How to resolve the algorithm MD5 step by step in the Lua programming language
You may also check:How to resolve the algorithm Magic squares of odd order step by step in the BASIC programming language
You may also check:How to resolve the algorithm 100 doors step by step in the GAP programming language
You may also check:How to resolve the algorithm Apply a callback to an array step by step in the Component Pascal programming language