From: David Jacobs Date: 2011-02-24T07:12:33+09:00 Subject: Re: finding a tag in a binary file --bcaec53f2bd9d9dc7d049cfa5da6 Content-Type: text/plain; charset=ISO-8859-1 Hi Rob, I don't usually work with binary files, but I would imagine you could do something like this (untested): search_byte = 0b00100010 contents = File.binread('1DICOMDIR').bytes.to_a index = contents.index(search_byte) # I assume you want the next entry after name = contents[index.next] Then simply decode the name however is appropriate. David On Wed, Feb 23, 2011 at 4:28 PM, rob s. wrote: > Hi I'm a complete non programmer but willing to give it a try. > > I have a DICOMDIR (medical imaging file) which has various tags in, > following a tag ie 0010, 0010 is the "patient name", "study date" > 0008,0020 is another. > > I have several DICOMDIR and I would like to extract just a few bits of > information from them to a .txt file, the files average size is about > 343 KB as its full of other information as well which I don't need. Each > file has amongst other things a list of about 10 names, scan dates etc. > > So far I've managed to read the file into an array using > > contentsArray=[] #open new array empty > > open('1DICOMDIR', 'rb') { |f| f.each_byte { |f| contentsArray.push f } } > > This gets the info into an array > > although its a hex file it displays the contents in decimal, but they > correspond to the hex codes I've seen in a hex editor... > > My problem is I don't know how to detect 0010,0010 ? then extract the > name. Can anyone help, I've looked all over the web but not finding > anything to help me much. Thanks a lot > > -- > Posted via http://www.ruby-forum.com/. > > --bcaec53f2bd9d9dc7d049cfa5da6--