From: Mark Hubbart Date: 2005-02-01T17:03:41+09:00 Subject: Re: split string On Tue, 1 Feb 2005 10:28:33 +0900, Cai Li wrote: > > -----BEGIN PGP SIGNED MESSAGE----- > Hash: SHA1 > > > > > This is not a splitting issue but an output issue. Apparently you > did > > something like "p array", i.e. used String#inspect. Try to do > "puts > > array" - if your environment supports chinese chars then that > should yield > > the expected output. > > > > Thank you Robert,your suggestion is useful.But,what is the > reason?Because > String#inspect does a silly thing in converting the origin string to > a string > containing a "human-readable" representation of it? Silly or not, it's the default behavior. By default, any non-ascii characters are escaped in inspected strings - it's assumed that your terminal can't display anything but ascii. But this is overrideable behavior: set the kcode ($KCODE="u") at the top of your script, and it should use the actual characters, where available. This turns on UTF-8 interpretation of characters. Also, it seems that some people use p( stuff ) without realizing that it it like calling puts( stuff.inspect ). #inspect, and therefore p, are primarily debugging tools, intended for use when you want to see *exactly* what is in the string. This means that unless you tell ruby differently, it assumes your strings are in ascii format, and #inspect escapes other characters accordingly. It should escape all whitespace other than normal spaces, all control characters, and all bytes that are not valid characters for the current KCODE. HTH, Mark > > -----BEGIN PGP SIGNATURE----- > Version: GnuPG v1.2.1 (MingW32) - WinPT 0.7.96rc1 > > iD8DBQFB/tsXVLC4xCNBi2kRAjJNAJ40XOMxiXD+3BFIhDzwgtHdGdgh7QCeLGZz > AZsrjOrruOuQDJImM+kgJdA= > =Bx6J > -----END PGP SIGNATURE----- > >