Path: csiph.com!x330-a1.tempe.blueboxinc.net!usenet.pasdenom.info!news.dougwise.org!nntpfeed.proxad.net!proxad.net!feeder1-2.proxad.net!usenet-fr.net!de-l.enfer-du-nord.net!feeder2.enfer-du-nord.net!talisker.lacave.net!lacave.net!not-for-mail From: 7stud -- Newsgroups: comp.lang.ruby Subject: Re: splitting binary data Date: Wed, 20 Apr 2011 12:54:07 -0500 Organization: Service de news de lacave.net Lines: 34 Message-ID: References: NNTP-Posting-Host: bristol.highgroove.com Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 7bit X-Trace: talisker.lacave.net 1303322085 18045 65.111.164.187 (20 Apr 2011 17:54:45 GMT) X-Complaints-To: abuse@lacave.net NNTP-Posting-Date: Wed, 20 Apr 2011 17:54:45 +0000 (UTC) In-Reply-To: X-Received-From: This message has been automatically forwarded from the ruby-talk mailing list by a gateway at comp.lang.ruby. If it is SPAM, it did not originate at comp.lang.ruby. Please report the original sender, and not us. Thanks! For more details about this gateway, please visit: http://blog.grayproductions.net/categories/the_gateway X-Mail-Count: 381945 X-Ml-Name: ruby-talk X-Rubymirror: Yes X-Ruby-Talk: Xref: x330-a1.tempe.blueboxinc.net comp.lang.ruby:3261 hroyd hroyd wrote in post #993957: > Hello > > First post (i am new to ruby :-)). Can you help? > > I am using eventmachine to read in TCP segments off the network. I read > in a TCP segment that contains 4 messages. The TCP segment binary data > is shown below, where > \xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\ is the > marker for each message. I would like to split the data intot he 4 > messages, but am having trouble doing so. When I split the data, the > whole message gets inserted into the first array element. I'm not seeing that. Your message starts with the delimiter, so the first element of the array will be a blank string: str = "\xFF\xFF" + "\x61" + "\xFF\xFF" + "\x62" + "\xFF\xFF" + "\x63" + "\xFF\xFF" + "\x64" pattern = "\xFF\xFF" p str.split(pattern) --output:-- ["", "a", "b", "c", "d"] -- Posted via http://www.ruby-forum.com/.