Split a character string based on change of character: Difference between revisions

m
Line 318:
 
=={{header|Amazing Hopper}}==
VERSION 1: string
<syntaxhighlight lang="c">
#include <basico.h>
 
#define INICIO 1
#define CHARS "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789\"+-/ \\:,;:_*"
 
algoritmo
objetivo = "gHHH5YY\"\"++ ///,,,\\", indice=0
largo=0, sublargo=0, v=0
 
#( largo = len(indice:=(onechar(CHARS,objetivo))) )
 
t=0, nuevo=""
para cada caracter ( v, indice, largo )
#(t = replicate(v, sublargo := ((poschar(INICIO, v, objetivo) - 1 ) ) ))
#(nuevo = cat( cat(nuevo, t), ", "))
objetivo+=sublargo
siguiente
 
imprimir( "NEW STRING=\n", nuevo,NL)
 
terminar
</syntaxhighlight>
{{out}}
<pre>
$ hopper3 basica/splitrep.bas
NEW STRING=
g, HHH, 5, YY, "", ++, , ///, ,,,, \,
</pre>
 
 
VERSION 2: arrays
<syntaxhighlight lang="c">
 
Line 345 ⟶ 379:
{{out}}
<pre>
$ hopper3 basica/splitrepsplitrep2.bas
LISTA=
g,HHH,5,YY,"",++, ,///,,,,,,\
543

edits