Skip to main content.
home | support | download

Back to List Archive

Re: Detecting multibyte/wide characters?

From: Bill Schell <friedfish(at)not-real.optonline.net>
Date: Mon Oct 04 2004 - 17:51:11 GMT
We prefer to be called swisheans. :-)

This function should do what you want, assuming you want
to know if you have any multibyte characters in a string.

use bytes();

sub string_has_multibyte_chars {
    my ($string) = @_;
    return 1 if (length($string)  < bytes::length(string));
    return 0;
}

Note that you must have the 'use' line exactly that way.
If you just say 'use bytes', the all of your calls to length
will be to bytes::length in the current lexical scope.


J Robinson wrote:

>Hello swisheites:
>
>I have a question related to swish-e, if someone in
>this knowledgable group might know the answer:
>
>Suppose I have word in a perl scalar ($w). 
>
>How can I detect if $w contains multibyte or 'wide'
>characters?  
>
>Thanks in advance if anyone knows. I suppose this
>might be in a faq somewhere but I couldn't find it.
>Thanks again.
>jrobinson
>
>
>		
>__________________________________
>Do you Yahoo!?
>New and Improved Yahoo! Mail - Send 10MB messages!
>http://promotions.yahoo.com/new_mail 
>
>  
>
Received on Mon Oct 4 10:51:29 2004