From: "Iñaki Baz Castillo" Date: 2009-04-04T01:39:53+09:00 Subject: Problem with String encoding when modifying it in C method 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). -------------------------------------------------------------------------------- irb> hname = "record-rouTE-€" "record-rouTE-€" irb> hname.encoding # irb> hname2 = hname.multi_capitalize "Record-Route-\xE2\x82\xAC" <------- !!! irb> hname2.encoding # <------- !!! irb> hname2.force_encoding("utf-8") "Record-Route-€" irb> hname2.encoding # -------------------------------------------------------------------------------- What should I add to my C method to mantain the UTF-8 codification after the changes in the string? Could I invoke the C "force_encoding()" function from the C code before returning the modified string? How to invoke it? Thanks a lot. -- Iñaki Baz Castillo