in reply to substr + utf

substr works on characters, not bytes, so you don't have to do anything special.

Replies are listed 'Best First'.
Re^2: substr + utf
by b888 (Beadle) on Aug 18, 2005 at 16:19 UTC

    Made several tests before posting - at least on my PC it works with utf8 symbols as if it is 2 chars.
    Maybe it depends on some OS settings?

      Are you sure the string is actually unicode? I think you interpreted every byte of your input as a character instead of interpreting your input as a unicode string. I'm not sure how to convert from one to the other.

      Maybe it depends on some OS settings?

      I doubt it. Try the following code.

      # $str = Approximation of "Eric" in Katakana. $str = "\x{30A8}\x{30FC}\x{30EA}\x{30AF}"; print(length($str), "\n"); # 4 $ch = substr($str, 0, 1); print(($ch eq "\x{30A8}" ? "equal" : "not equal"), "\n"); # equal