harangzsolt33 has asked for the wisdom of the Perl Monks concerning the following question:
if ($STRING =~ m/[^\x00-\xFF]{1}/) { ... }
OR MAYBE:
if (length($STRING) > ($STRING =~ tr|\x00-\xFF|\x00-\xFF|)) { ... }
I can't think of anything better. Maybe this, but I bet it's slow:
sub isUnicode { my $L = defined $_[0] ? length($_[0]) : 0; for (my $i = 0; $i < $L; $i++) { ord(substr($_[0], $i, 1)) < 256 or return 1; } return 0; }
|
---|
Replies are listed 'Best First'. | |
---|---|
Re: How to test if a string is unicode string?
by jwkrahn (Abbot) on Apr 04, 2025 at 05:26 UTC | |
Re: How to test if a string is unicode string?
by cavac (Prior) on Apr 04, 2025 at 12:11 UTC | |
by harangzsolt33 (Deacon) on Apr 05, 2025 at 12:01 UTC | |
Re: How to test if a string is unicode string?
by ikegami (Patriarch) on Apr 04, 2025 at 15:36 UTC |