albert has asked for the wisdom of the Perl Monks concerning the following question:
This is a follow-up to my related question Counting text with ligatures.
I have two columns of text which might contain a grapheme (such as ff, ffi). How can find a substring at a fixed column position, counting the graphemes as '1' each? In this example, I was hoping to print '0123456789' for each line.
Note: I inserted the code as pre-formatted, since the code-tag encodes the graphemes. I tried to fix using substr from Unicode::GCString, but that didn't work as I hoped.
use strict; use warnings; use Unicode::GCString; while (my $s = <DATA>){ chomp($s); my $right = substr $s, 10; print $right, "\n"; # my $gcs = Unicode::GCString->new($s); # my $right2 = $gcs->substr(10); # print $right2, "\n"; } __DATA__ 01234567 0123456789 0123456ff 0123456789 0123456ffi 0123456789 012ff4ffi67 0123456789
|
---|
Replies are listed 'Best First'. | |
---|---|
Re: Finding substrings of fixed width text with graphemes
by haukex (Archbishop) on Sep 13, 2017 at 16:18 UTC | |
by albert (Monk) on Sep 13, 2017 at 16:35 UTC |
Back to
Seekers of Perl Wisdom