From: James Masters Date: 2010-05-06T11:20:08+09:00 Subject: Re: How can I call String#replace (rb_str_replace()) in C API? > > How can I do this with the Ruby C API?  I looked at rb_str_replace in > > string.c; however, that is not a public function in the C API.  After > > Are you using ruby 1.8 or 1.9? 1.9 makes rb_str_replace non-static and > declares it in intern.h. I don't see it in 1.8's intern.h, so its very Unfortunately I am using Ruby 1.8. > > I'm really just looking for a way to take a Ruby string VALUE and > > replace the contents of that object with a C string in the most > > efficient method possible.  Can someone help me in doing this or at > > least point me in the right direction? > > One other option is to fiddle directly with the fields of struct > RString, but I don't recommend that unless you're really dedicated. I am thinking about doing this but it would be a pain and probably dangerous as you have mentioned. I can probably put something together with good performance by tweaking the pointer location and string length but I'll need to get more familiar with the Ruby code before I attempt something like this. One good thing is that I am creating the Ruby string to be used as the replacement myself in the C+ + code on my own so I shouldn't need to do type checking. If anyone has any pointers on where to find some of the underlying Ruby C data structures (e.g. ELTS_SHARED and STR_ASSOC flags) then I could use it. Thanks for your reply... it was helpful to at least confirm the issue at hand.