From: Bill Kelly Date: 2001-12-29T09:44:49+09:00 Subject: [ruby-talk:29609] Re: Stripping substrings from strings From: "Paul Vallance" > I would like to put the string returned via the TCP Server to my > rubyscript into a variable (@readdata) and strip the words "TCP/XT > OK" from the end of it and update the variable, then use the contents > of this variable in a following send... something like below... . I > thought str.gsub would do it, ie replace the substring "TCP/XT OK" > with an empty string (though I'm sure "" is not right syntax for an > empty string). "" is indeed an empty string in Ruby, as is '' or %q{} etc. > > #!/usr/bin/env ruby > > require 'socket' > t = TCPSocket.new("192.168.0.178",13) > > t.send("/firstbox\n",0) > @readdata = t.recv(30) > puts @readdata // which is "123456789 TCP/XT OK" > v = @readdata > v.str.gsub!(TCP//XT OK,"" ) I believe recv() returns a String already so, should be no need for the v.str. as above... Try perhaps: v.gsub!(/TCP\/XT OK/, "") > t.send("/ispicbox(#v )\n",0) Hope this helps, Regards, Bill