From: Robert Klemme Date: 2005-01-31T21:50:46+09:00 Subject: Re: split string "Cai Li" schrieb im Newsbeitrag news:000901c50791$b54c8370$8caba2d3@lcai... > -----BEGIN PGP SIGNED MESSAGE----- > Hash: SHA1 > > My job is to split the following string which contains some chinese > chars(GB code) and make an array: > > "sz000503,????,2005-01-31 15:01:01, color=009933>11.780,11.950,11.800, color=009933>-0.170,11.640,11.930, color=009933>-1.42%,61454,7231.56,11.770,11.790, color=009933>-60.52%,11.77 / 96,11.76 / 197,11.75 / 195,11.79 > / 177,11.80 / 611,11.81 / 424,11.73 / 85,11.72 / 70,11.82 / 528,11.83 > / 873" > > my own script looks like this: > def make_array(orig_string) > > rb_array = Array.new > elements = '' > orig_string.each_byte {|s| > if sprintf("%c",s) != ',' then > elements = elements + sprintf("%c",s) > else > rb_array.push(elements) > elements = '' > end > } > return rb_array > end Btw, "str.split(/,/)" should do exactly the same and is more efficient. > with the following results: > ["sz000503", "\272\243\272\347\277\330\271\311", "2005-01-31 > 15:01:01", " olor=009933>11.780", "11.950", "11.800", " color=009933>-0.170 >", "11.640", "11.930", "-1.42%", "61454", > "7231.56", > "11.770", "11.790", "-60.52%", "11.77 / > 96", "11.76 / > 197", "11.75 / 195", "11.79 / 177", "11.80 / 611", "11.81 / 424", > "11.73 / 85", > "11.72 / 70", "11.82 / 528"] > > Almost right except chinese chars.Then how to save chinese? Err, what exactly is the problem? I don't see chinese characters, which is probably doe to my installed encodings. But what result do you want to get? Kind regards robert > -----BEGIN PGP SIGNATURE----- > Version: GnuPG v1.2.1 (MingW32) - WinPT 0.7.96rc1 > > iD8DBQFB/iZGVLC4xCNBi2kRAngyAJ4lJew59t3OpUYFeY3rdt7cW0C/wgCdFk8g > owog0jOeOyJq2OsvbfJlpvk= > =9Unz > -----END PGP SIGNATURE----- > >