Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.forth > #60032

Re: Rosetta: Split a character string based on change of character

From "Robert L." <No_spamming@noWhere_7073.org>
Newsgroups comp.lang.forth
Subject Re: Rosetta: Split a character string based on change of character
Date 2017-05-29 22:40 +0000
Organization Aioe.org NNTP Server
Message-ID <ogi80p$15p$1@gioia.aioe.org> (permalink)
References <oghm17$12gq$1@gioia.aioe.org>

Show all headers | View raw


On 5/29/2017, Robert L. wrote:

> > Split a (character) string into comma (plus a blank) delimited
> > strings based on a change of character (left to right).
> 
> > For instance, the string: 
> > 
> >  gHHH5YY++///\ 
> > 
> > should be split and show: 
> > 
> >  g, HHH, 5, YY, ++, ///, \ 
> 
> puts "gHHH5YY++///\\".chars.slice_when{|a,b| a != b}.map(&:join).
>   join ", "
> 
>  ===>
> g, HHH, 5, YY, ++, ///, \
> 
> 
> In Forth?

(string-join
  (let go ((s "gHHH5YY++///\\"))
    (if (string=? "" s)
      '()
      (let ((m (rxmatch #/^(.)\1*/ s)))
        (cons (rxmatch-substring m)
              (go (rxmatch-after m))))))
  ", ")

 ===>
"g, HHH, 5, YY, ++, ///, \\"

-- 
In Denmark, a teenage girl was attacked by a Muslim immigrant.... She fought
back, and used a can of pepper spray ... against him....  In the aftermath she
was told that she faced prosecution, as pepper spray is illegal in Denmark.
www.europeancivilwar.com/anarcho-tyranny-and-the-logistical-class

Back to comp.lang.forth | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread


Thread

Rosetta: Split a character string based on change of character "Robert L." <No_spamming@noWhere_7073.org> - 2017-05-29 17:33 +0000
  Re: Rosetta: Split a character string based on change of character "Robert L." <No_spamming@noWhere_7073.org> - 2017-05-29 22:40 +0000
    Re: Rosetta: Split a character string based on change of character "Robert L." <No_spamming@noWhere_7073.org> - 2017-05-30 07:26 +0000
      Re: Rosetta: Split a character string based on change of character Julian Fondren <julian.fondren@gmail.com> - 2017-05-30 01:01 -0700

csiph-web