- 浏览: 174670 次
- 来自: ...
文章分类
最新评论
-
fsword:
同事拿着试了一下,说是把第五步放到第二步之前就可以了
在windows下安装ruby1.9.2,rails3.0.3和DevKit--转 -
dothwinds:
[flash=200,200][/flash][url][/u ...
打包ruby or rails成exe(英文)
The Difference Between Binary and ASCII Files; Converting them
At heart all files are binary files -- that is, a collection of 1s and 0s. But there's a subset of binary files we call ASCII, or plain text files. ASCII is short for American Standard Code for Information Interchange, which allocates a number to each letter, digit and symbol. A plain text file contains no formatting codes whatsoever, no fonts, bold, italics or underlines, headers, footers or graphics. The only 'formatting' that can be applied is to use spaces to pad lines out so that they are centered or right justified, or to add extra blank lines.
Let's look at some example - different file types containing the word 'hello' followed by a new line. To see the differences, we will use a hex display, to show us exactly what is in each file, and highlight the word hello in the output so we can see where it appears. A hex display shows us the offset, ASCII code and the actual characters contained in a file (where those characters are printable - it shows a period where they are not). These hex displays were generated by TextPipe Pro (Filters Menu\Convert\Hex dump).
Plain Text File - hello.txt (7 bytes long)
This is the simplest file - the ASCII codes for the letters 'hello' followed by the ASCII codes for a carriage return and line feed.
00000000 68 65 6C 6C 6F 0D 0A hello..
Rich Text Format (RTF) File - hello.rtf (168 bytes long)
You can see that an RTF file includes lots of extra guff. Generally, all the letters of the word will be together. However, if you have two or more words, other codes can appear between the words, making them difficult to locate.
00000000 7B 5C 72 74 66 31 5C 61 6E 73 69 5C 61 6E 73 69 {\rtf1\ansi\ansi 00000010 63 70 67 31 32 35 32 5C 64 65 66 66 30 5C 64 65 cpg1252\deff0\de 00000020 66 6C 61 6E 67 33 30 38 31 7B 5C 66 6F 6E 74 74 flang3081{\fontt 00000030 62 6C 7B 5C 66 30 5C 66 73 77 69 73 73 5C 66 63 bl{\f0\fswiss\fc 00000040 68 61 72 73 65 74 30 20 41 72 69 61 6C 3B 7D 7D harset0 Arial;}} 00000050 0D 0A 7B 5C 2A 5C 67 65 6E 65 72 61 74 6F 72 20 ..{\*\generator 00000060 4D 73 66 74 65 64 69 74 20 35 2E 34 31 2E 31 35 Msftedit 5.41.15 00000070 2E 31 35 30 33 3B 7D 5C 76 69 65 77 6B 69 6E 64 .1503;}\viewkind 00000080 34 5C 75 63 31 5C 70 61 72 64 5C 66 30 5C 66 73 4\uc1\pard\f0\fs 00000090 32 30 20 68 65 6C 6C 6F 5C 70 61 72 0D 0A 5C 70 20 hello\par..\p 000000A0 61 72 0D 0A 7D 0D 0A 00 ar..}...
Microsoft Word Document - hello.doc (19,968 bytes long)
The file below, even without any formatting, is huge, so we've removed large sections of it for clarity. A major point we have to make here is that Word relies on the exact position of various aspects of the file being fixed, such as font tables, symbol tables and other internal references. If these positions are changed (e.g. by searching for 'hello' and replacing it with a shorter string such as 'bye' or a longer string such as 'hello there') then the document will be corrupted and MS Word will not be able to load the document again. Recovery may not be possible. This is why you CANNOT use a text editor or text tool on Word documents. You must use a specific tool that knows how to maintain the correct offsets, such as WordPipe for MS Word, ExcelPipe for MS Excel or PowerPointPipe for MS PowerPoint.
An additional point to note is that the word 'Symbol' is stored in the Word document in Unicode format (see below), so a text editor or text tool will not find it. Since this file contains mixed sections of ASCII and Unicode, it is crucial that the file positions are left unchanged.
00000000 D0 CF 11 E0 A1 B1 1A E1 00 00 00 00 00 00 00 00 ÐÏ.ࡱ.á........ 00000010 00 00 00 00 00 00 00 00 3E 00 03 00 FE FF 09 00 ........>...þÿ.. 00000020 06 00 00 00 00 00 00 00 00 00 00 00 01 00 00 00 ................ ... 000009F0 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ................ 00000A00 68 65 6C 6C 6F 0D 0D 00 00 00 00 00 00 00 00 00 hello........... 00000A10 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ................ ... 00001A40 00 53 00 79 00 6D 00 62 00 6F 00 6C 00 00 00 33 .S.y.m.b.o.l...3 ... 00004DF0 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ................
Unicode Plain Text File - hello.txt (16 bytes long)
ASCII is being replaced in many applications by Unicode, which uses 16 bits (2 bytes) per character to represent non-Roman alphabets like Japanese, Chinese, and Cyrillic. A text editor or text tool won't find 'hello' in this file. TextPipe Pro provides Unicode search and replace facilities, in addition to ASCII search and replace, so it can find both forms of 'hello'.
00000000 FF FE 68 00 65 00 6C 00 6C 00 6F 00 0D 00 0A 00 ÿþh.e.l.l.o.....
Convert binary files to text files
Now, to convert a binary file to a useful text form, you need to strip out all the binary characters - the formatting, control and other gobbledygook stuff. TextPipe Pro provides a simple filter for this under Filters\Remove\Binary characters.
You can also generate your own custom filter that only removes the binary characters you specify by using Filters\Maps\New map.
You may freely link to this page, but you may not copy its content.
-------------------------------------------------------------------------------------------------------------------------------
from http://book.77169.org/ask2/ask112678.htm
从文件编码的方式来看,文件可分为ASCII码文件和二进制码文件两种。
ASCII文件也称为文本文件,这种文件在磁盘中存放时每个字符对应一个字节,用于存放对应的ASCII码。例如,数5678的存储形式为:
ASC码:
00110101 00110110 00110111 00111000
↓ ↓ ↓ ↓
十进制码:
5 6 7 8 共占用4个字节。ASCII码文件可在屏幕上按字符显示,
例如源程序文件就是ASCII文件,用DOS命令TYPE可显示文件的内容。 由于是按字符显示,因此能读懂文件内容。
二进制文件是按二进制的编码方式来存放文件的。 例如, 数5678的存储形式为:
00010110 00101110只占二个字节。二进制文件虽然也可在屏幕上显示, 但其内容无法读懂。
1949存储为079D(对应二进制为0000 0111 1001 1101,即十进制1949的等值数)
发表评论
-
ruby知识点滴
2011-04-25 16:20 6891、加入文件所在路径 $: << (" ... -
ruby读取SQLite的图片数据并插入word中
2011-04-24 11:18 1097表的结构请参看 http://xineohpanihc ... -
SQLite/Ruby FAQ --转
2011-04-24 10:18 904SQLite/Ruby FAQ How do I ... -
ruby 将图片读入sqlite,再取出
2011-04-24 09:32 1539# -*- coding: utf-8 -*- req ... -
ruby 读写图片文件
2011-04-24 09:25 1459# -*- coding: utf-8 -*- f ... -
Ruby操作Sqlite详解示例 --转
2011-04-23 21:31 2661A Quick Guide to SQLite an ... -
在windows下安装ruby1.9.2,rails3.0.3和DevKit--转
2011-04-23 15:54 1814在windows下安装ruby1.9.2,rails3 ... -
ruby操作word--输入文字和设置格式
2011-04-23 10:19 1683# coding: utf-8require "wi ... -
ruby操作sqlite
2011-04-23 10:14 840require 'sqlite3'db = SQLite3:: ... -
Ruby操作word时遇到中文问题
2011-04-22 17:56 696# coding: utf-8 require &qu ... -
打包ruby or rails成exe(英文)
2008-11-14 12:34 2223ruby2exe有两种选择: 1、使用rubyscript2e ... -
Ruby操作excel
2008-11-13 16:34 3647一、新建并打开excel文件 #newEmptyExcel.r ...
相关推荐
ruby a script code setup file
深度剖析 Ruby vs Java 误区
ruby test_file class des
ruby代码ruby代码ruby代码ruby代码ruby代码ruby代码ruby代码ruby代码
Text Processing with Ruby ruby文档解析 完整版 完整版
ruby DBI ruby DBI ruby DBIruby DBI ruby DBI ruby DBIruby DBI ruby DBI ruby DBIruby DBI ruby DBI ruby DBIruby DBI ruby DBI ruby DBIruby DBI ruby DBI ruby DBIruby DBI ruby DBI ruby DBIruby DBI ruby DBI ...
Refile - 一个现代的文件上传Ruby应用程序库。它是简单的,但功能强大。
《Ruby完全自学手册》是一本完全覆盖Ruby和Ruby on Rails的完全自学手册。《Ruby完全自学手册》的特色是由浅入深、循序渐进,注重理论和实践的结合。虽然定位为入门手册,但是依然涉及许多高级技术和应用,覆盖到的...
ruby2ruby 提供一些用来根据 RubyParser 兼容的 Sexps 轻松生成纯 Ruby 代码的方法。可在 Ruby 中轻松实现动态语言处理。 标签:ruby2ruby
ruby源代码 ruby源代码 ruby源代码 ruby源代码2
Ruby编程,Ruby编程,Ruby编程,Ruby编程,Ruby编程,
ruby源代码 ruby源代码 ruby源代码 ruby源代码4
ruby笔记1ruby笔记1ruby笔记1ruby笔记1ruby笔记1ruby笔记1
ruby-build - 编译和安装Ruby
ruby源代码 ruby源代码 ruby源代码 ruby源代码3
ruby打包文件ruby打包文件ruby打包文件ruby打包文件ruby打包文件ruby打包文件ruby打包文件ruby打包文件ruby打包文件
The book also includes a long and thorough introduction to the rich API of the Ruby platform, demonstrating -- with heavily-commented example code -- Ruby's facilities for text processing, numeric ...
ruby interpreter 原理探討 At first glance, learning how to use Ruby can seem fairly simple. Developers around the world find Ruby’s syntax to be graceful and straightforward. You can express ...
内含以下4个文档: 1、Addison.Wesley.The.Ruby.Way.2nd.Edition.Oct.2006.chm 2、O'Reilly.Learning.Ruby.May.2007.chm 3、Programming Ruby 2e.pdf 4、ruby中文文档.chm
Ruby,一种简单快捷的面向对象(面向对象程序设计)脚本语言,在20世纪90年代由日本人松本行弘(Yukihiro Matsumoto)开发,遵守GPL协议和Ruby License。它的灵感与特性来自于 Perl、Smalltalk、Eiffel、Ada以及 Lisp ...