Dave's Brain

Browse - programming tips - perl detect accented characters in a 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";
		}
	}
What this info useful to you? You can donate to say thanks

Add a comment

Sign in to add a comment
Copyright © 2008-2012, 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.
Advertisements: