Dave's Brain

Browse - Programming Tips - Best way to detect accented characters in a Perl string?

Date: 2011aug13
Language: perl

Q.  Best way to detect accented characters in a Perl string?

A.  Use the ever powerful match:

sub hasAccents($) { my($a) = @_; return $a =~ m/[\x7F-\xFF]/s } sub exampleUse() { my $a = "line one\nhello\x88"; if (hasAccents($a)) { print "There are accents\n"; else { print "Just regular ASCII\n"; } }

Add a comment

Sign in to add a comment
Copyright © 2008-2017, dave - Code samples on Dave's Brain is licensed under the Creative Commons Attribution 2.5 License. However other material, including English text has all rights reserved.