From: Yang Bob Date: 2007-08-01T00:21:30+09:00 Subject: Re: How to substitute a string with different size ------=_Part_34678_7195852.1185895292526 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: 7bit Content-Disposition: inline Hi Li, What do you mean 'unpreditable result'? Do you mean that the size of 'str' object is not correct? 2007/7/31, Li Chen : > > Hi all, > > I deal with a mixture of text and binary file. I want to search a > pattern in the string and replace it with a new pattern, then write to a > new file. I use the following script(only part of the script) > > str.gsub!(/old_pattern/,"new_pattern") > file.seek(-str.length,IO::SEEK_CUR) > file.print str > > It works fine if the both old_pattern and new_pattern are the same size. > But it will produce unpreditable result if the sizes are different. I > wonder if any one out there knows how to explain it and provide a Ruby > way solution. > > Thanks, > > Li > -- > Posted via http://www.ruby-forum.com/. > > ------=_Part_34678_7195852.1185895292526--