From: daz Date: 2003-07-23T15:02:31+09:00 Subject: Re: Should String#strip take a parameter? "Xiangrong Fang" wrote: > Hi, > > I have a question regarding strip. I wrote a DLL in other language, and > used the following to call the dll function in ruby: > > arg = " " * 100 > myfunc.Call(arg) > > after that arg may contain a string such as: > > "return value\000" > > I used strip, but the strip does not strip away terminating null > character... > > Am I doing something wrong? If I suggest that strip should also strip > the \000, is it a good idea or not? > > Shannon > The only reason for thinking #strip might be relevant in this situation is that you initialised your buffer with spaces. class String def sz_cut! # cut at string-zero terminator replace(self[/\A[^\0]*/]) end end p "return value\000 garbage".sz_cut! #-> "return value" .... works more generally. But I can't see a problem with treating "\0" as whitespace in #rstrip until the day someone wants to pass it on as a C-string, gets an error, then remembers to add it back ;-) string << 0 daz