What's the difference between UTF-8 and UTF-8 without BOM?
https://stackoverflow.com/questions/2223882/whats-the-difference-between-utf-8-and-utf-8-without-bom
Answer1
The UTF-8 BOM is a sequence of Bytes at the start of a text-stream (EF BB BF) that allows the reader to more reliably guess a file as being encoded in UTF-8.
Normally, the BOM is used to signal the endianness of an encoding, but since endianness is irrelevant to UTF-8, the BOM is unnecessary.
According to the Unicode standard, the BOM for UTF-8 files is not recommended:
2.6 Encoding Schemes
... Use of a BOM is neither required nor recommended for UTF-8, but may be encountered in contexts where UTF-8 data is converted from other encoding forms that use a BOM or where the BOM is used as a UTF-8 signature. See the “Byte Order Mark” subsection in Section 16.8, Specials, for more information.
Answer2
The other excellent answers already answered that:
- There is no official difference between UTF-8 and BOM-ed UTF-8
- A BOM-ed UTF-8 string will start with the three following bytes.
EF BB BF
- Those bytes, if present, must be ignored when extracting the string from the file/stream.
But, as additional information to this, the BOM for UTF-8 could be a good way to "smell" if a string was encoded in UTF-8... Or it could be a legitimate string in any other encoding...
For example, the data [EF BB BF 41 42 43] could either be:
- The legitimate ISO-8859-1 string "ABC"
- The legitimate UTF-8 string "ABC"
So while it can be cool to recognize the encoding of a file content by looking at the first bytes, you should not rely on this, as show by the example above
Encodings should be known, not divined.
评论
You understood correctly. The string [EF BB BF 41 42 43] is just a bunch of bytes. You need external information to choose how to interpret it. If you believe those bytes were encoded using ISO-8859-1, then the string is "ABC". If you believe those bytes were encoded using UTF-8, then it is "ABC". If you don't know, then you must try to find out. The BOM could be a clue. The absence of invalid character when decoded as UTF-8 could be another... In the end, unless you can memorize/find the encoding somehow, an array of bytes is just an array of bytes.
Convert a file to utf-8, but still shown as ascii
ASCII is a subset of UTF-8, so all ASCII files are already UTF-8 encoded. The bytes in the ASCII file and the bytes that would result from "encoding it to UTF-8" would be exactly the same bytes. There's no difference between them, so there's no need to do anything.
It looks like your problem is that the files are not actually ASCII. You need to determine what encoding they are using, and transcode them properly.
What's the difference between UTF-8 and UTF-8 without BOM?的更多相关文章
- UTF—8与UTF—8(无bom)格式
BOM——Byte Order Mark,就是字节序标记 在UCS 编码中有一个叫做"ZERO WIDTH NO-BREAK SPACE"的字符,它的编码是FEFF.而FFFE在U ...
- Unicode、UTF-8 和 ISO8859-1到底有什么区别
说明:本文转载于新浪博客,旨在方便知识总结.原文地址:http://blog.sina.com.cn/s/blog_673c81990100t1lc.html 本文主要包括以下几个方面:编码基本知识, ...
- Unicode、UTF-8 和 ISO8859-1
Unicode.UTF-8 和 ISO8859-1到底有什么区别 1.本文主要包括以下几个方面:编码基本知识,java,系统软件,url,工具软件等. 在下面的描述中,将以"中文" ...
- UniEAP UTF 用户手册 (引擎)
目录 第1章 概述 5 1.1 术语解释 5 第2章 测试文件组织 6 2.1 测试执行文件详解 7 2.1.1 参数配置 7 2.1.2 测试报告配置 9 2.1.3 浏览器类型配置 9 2.1.4 ...
- Python3中文教程
搜索 此文档来源自网络 安装 PYTHON❝ Tempora mutantur nos et mutamur in illis. (时光流转,吾等亦随之而变.) ❞ — 古罗马谚语 深入欢迎来到 Py ...
- linux实践——字符集
一.ASCII码 首先是看得懂ASCII码表: 二 八 十 十六 缩写/字符 0000 0000 0 0 00 NUL(null) 0000 0001 1 1 01 SOH(start of head ...
- GBK、GB2312、iso-8859-1之间的区别
转自:http://blog.csdn.net/jerry_bj/article/details/5714745 GBK.GB2312.iso-8859-1之间的区别 GB2312,由中华人民共和国政 ...
- 【转】关于Python脚本开头两行的:#!/usr/bin/python和# -*- coding: utf-8 -*-的作用 – 指定文件编码类型
原文网址:http://www.crifan.com/python_head_meaning_for_usr_bin_python_coding_utf-8/ #!/usr/bin/python 是用 ...
- 【转】Java编程之字符集问题研究
发现这是对字集说得最明了的一篇文章了. 转发自:http://tomcat-oracle.iteye.com/blog/2037160 1. 概述 本文主要包括以下几个方面:编码基本知识,java,系 ...
- Android之单复选框及Spinner实现二级联动
一.基础学习 1.图形学真的很神奇啊....查了些资料做出了3D云标签,哈哈...其实直接拿来用的,我们要效仿鲁迅先生的拿来主义,嘿嘿~~3D标签云就是做一个球面,然后再球面上取均匀分布的点,把点坐标 ...
随机推荐
- OSX终端 命令行的一些基本操作
本文转载至 http://blog.csdn.net/xdrt81y/article/details/24058959 osx终端命令 OSX终端 命令行的一些基本操作终端 命令行的一些基本操作很多朋 ...
- python 之 多线程
一.多线程(具体可参照博文多进程---->http://www.cnblogs.com/work115/p/5621789.html) 1.函数式实现多线程 2.类实现多线程 3.多线程之线程锁 ...
- git 分回滚后无法合并代码问题
git reset & git revert 区别: 1. git revert是用一次新的commit来回滚之前的commit,git reset是直接删除指定的commit. 2. 在回滚 ...
- finereport---FineReport入门常见疑难点
一.入门介绍 二.入门需知 注意:开发人员可以设置DEBUG级别,有助于测试 三.数据准备 数据集sql中可以使用参数宏${}动态地生成过滤条件,${}中的语句在FineReport报表中执行,将${ ...
- 用户登陆状态,ios开发用户登陆
IOS开发之记录用户登陆状态,ios开发用户登陆 上一篇博客中提到了用CoreData来进行数据的持久 化,CoreData的配置和使用步骤还是挺复杂的.但熟悉CoreData的使用流程后,CoreD ...
- jQuery选择器-常用
jQuery选择器-常用 1.基本选择器 $("#id") //ID选择器 $("div") //元素选择器 $(".classname") ...
- Linux(8)- nginx+uWSGI+virtualenv+supervisor 发布web服务器
一.理论梳理 WSGI是web服务器的网关接口,它是一个规范,描述了web服务器(下图中的WEB server)如何与web应用程序(下图中的Application)通信,以及web应用程序如何链接在 ...
- 从库函数解析STM32地址映射
STM32的存储映射是靠基地址和地址偏移实现的. 32位的M3有4GB的寻址空间,其中用于片上外设的有512MB,基地址为0x40000000. M3各外设基地址,包括片上外设.片上静态RAM和FLA ...
- Pantone色卡——安全装备的面板、丝印及铭牌颜色设计参考
可以参考上传文件<Pantone色卡电子版下载>
- 收藏:几种开源许可证的区别!——By 阮一峰制作
乌克兰程序员Paul Bagwell,画了一张分析图,下面是阮一峰制作的中文版,非常棒,绝对的好东西,收藏这张图供日后查看: