iterate over string (UAX #29)

  • A+
Category:Languages
say $s.substr($_, 1) for 0..^$s.chars 

is the shortest I can find. Can you golf it to a reasonable size and avoid the repetition?

Perl 5 is shorter: say for split //b{g}/, $s

 


The comb method without an argument will pick out every character, thus:

.say for $s.comb; 

Will do what is desired (and is shorter than the Perl 5 version too :-)).

Comment

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen: