in reply to Re: help needed in unicode displaying
in thread help needed in unicode displaying

dear monks, i saw the posts in "help needed in unicode displaying" and i tried to do some program.i came across the following problem.In the $target variable, I stored some chinese characters (for example three chinese characters), I tried to get first two chinese characters using substr $target,0 2 ; , but its not giving the appropriate answer. any one give me the solution to retrieve the first two chinese characters,

Replies are listed 'Best First'.
Re^3: help needed in unicode displaying
by graff (Chancellor) on Mar 10, 2006 at 23:12 UTC
    How about if you show us just enough code to demonstrate the problem -- i.e. assign characters to a scalar, apply substr to the scalar, print the result in some way -- and show us what you actually get as a result. (In the little snippet you showed, there should be a comma between the 0 and the 2.)

    For example, this should do what you intended:

    my $target = join("", map {chr()} ( 0x5434, 0x9547, 0x5b87 )); my $part = substr( $target, 0, 2 ); print " length of target = ", length($target); print "\n length of substr = ", length( $part ); print "\n $target\n $part\n";
    The length function should return the character counts (3 for $target, 2 for $part). If you are using a utf8-aware display window, you should see the two strings in Chinese characters (or redirect to a file, and view that in a utf8-capable display tool, like a browser).

    If you get something different, tell us what OS and perl version you have, and be specific about what you actually got.