From: KUBO Takehiro Date: 2009-04-04T19:32:31+09:00 Subject: Re: Problem with String encoding when modifying it in C method Hi, On Sat, Apr 4, 2009 at 1:39 AM, Iņaki Baz Castillo wrote: > Hi, I've added a method "multi_capitalize" to String class. This > method is done in C and basically modifies the string: > >  "record-roUTE".multi_capitalize => "Record-Route" > > The problem is that after the method execution, the new String has > ASCII-8BIT encoding, while the original string had UTF-8 (using Ruby > 1.9.1). rb_encoding *enc = rb_enc_get(original_string) /* create a new string with the encoding same with the original string */ return rb_enc_str_new(char_pointer, length, enc); rb_str_new() makes a ASCII-8BIT string.