Questions tagged [encoding]

Encoding is a set of predefined rules to reversibly transform a piece of information in a certain representation into a completely different representation. The other way round is called decoding. This tag is rather generic, but it is mainly used for binary encoding schemes such as base 64 and hexadecimal.

There are a lot of different applications:

  • which is how the computer represents characters like a and , which humans can recognize, into bytes, which computers can recognize.
  • which is used to transform between videos and bytes.
  • which is used to transform between plain text and valid URIs. Also known as .
  • which is used to transform between plain text and valid XML.
  • which is used to compress/decompress bytes.
24174 questions
121
votes
11 answers

java.sql.SQLException: Incorrect string value: '\xF0\x9F\x91\xBD\xF0\x9F...'

I have the following string value: "walmart obama " I am using MySQL and Java. I am getting the following exception: `java.sql.SQLException: Incorrect string value: '\xF0\x9F\x91\xBD\xF0\x9F...' Here is the variable I am trying to insert into: var1…
CodeKingPlusPlus
  • 15,383
  • 51
  • 135
  • 216
119
votes
9 answers

Character reading from file in Python

In a text file, there is a string "I don't like this". However, when I read it into a string, it becomes "I don\xe2\x80\x98t like this". I understand that \u2018 is the unicode representation of "'". I use f1 = open (file1, "r") text =…
Graviton
  • 81,782
  • 146
  • 424
  • 602
117
votes
8 answers

Replacement for stringByAddingPercentEscapesUsingEncoding in ios9?

In iOS8 and prior I can use: NSString *str = ...; // some URL NSString *result = [str stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding]; in iOS9 stringByAddingPercentEscapesUsingEncoding has been replaced with…
slavik
  • 1,341
  • 2
  • 11
  • 16
117
votes
12 answers

ruby 1.9: invalid byte sequence in UTF-8

I'm writing a crawler in Ruby (1.9) that consumes lots of HTML from a lot of random sites. When trying to extract links, I decided to just use .scan(/href="(.*?)"/i) instead of nokogiri/hpricot (major speedup). The problem is that I now receive a…
Marc Seeger
  • 2,717
  • 4
  • 28
  • 32
117
votes
9 answers

C# Convert string from UTF-8 to ISO-8859-1 (Latin1) H

I have googled on this topic and I have looked at every answer, but I still don't get it. Basically I need to convert UTF-8 string to ISO-8859-1 and I do it using following code: Encoding iso = Encoding.GetEncoding("ISO-8859-1"); Encoding utf8 =…
Daniil Harik
  • 4,619
  • 10
  • 55
  • 60
117
votes
1 answer

SyntaxError of Non-ASCII character

I am trying to parse xml which contains the some non ASCII cheracter, the code looks like below from lxml import etree from lxml import objectify content = u'
Order date                            :…
OpenCurious
  • 2,916
  • 5
  • 22
  • 25
111
votes
9 answers

Android. WebView and loadData

It's possible to use following method for content's setting of a web-view loadData(String data, String mimeType, String encoding) How to handle the problem with unknown encoding of html data?! Is there a list of encodings?! I know from my college…
Tima
  • 12,765
  • 23
  • 82
  • 125
110
votes
10 answers

Get a list of all the encodings Python can encode to

I am writing a script that will try encoding bytes into many different encodings in Python 2.6. Is there some way to get a list of available encodings that I can iterate over? The reason I'm trying to do this is because a user has some text that is…
Amandasaurus
  • 58,203
  • 71
  • 188
  • 248
106
votes
22 answers

Best way to encode text data for XML in Java?

Very similar to this question, except for Java. What is the recommended way of encoding strings for an XML output in Java. The strings might contain characters like "&", "<", etc.
Epaga
  • 38,231
  • 58
  • 157
  • 245
106
votes
8 answers

How to write UTF-8 in a CSV file

I am trying to create a text file in csv format out of a PyQt4 QTableWidget. I want to write the text with a UTF-8 encoding because it contains special characters. I use following code: import codecs ... myfile = codecs.open(filename,…
Martin
  • 1,236
  • 3
  • 9
  • 9
105
votes
11 answers

How to check encoding of a CSV file

I have a CSV file and I wish to understand its encoding. Is there a menu option in Microsoft Excel that can help me detect it OR do I need to make use of programming languages like C# or PHP to deduce it.
Vipul
  • 2,023
  • 2
  • 15
  • 12
105
votes
4 answers

Set Encoding of File to UTF8 With BOM in Sublime Text 3

When I open a file in Sublime Text 3, at the bottom I have an option to set the Character Encoding as shown in the screenshot. There is the option to set it to UTF-8 , which after doing some research means UTF-8 Without BOM, but I want to set it to…
J86
  • 14,345
  • 47
  • 130
  • 228
105
votes
11 answers

Node.js get image from web and encode with base64

I'm trying to fetch an image from the web and encode it with base64. What I have so far is this: var request = require('request'); var BufferList = require('bufferlist').BufferList; bl = new…
Aleksr9
  • 1,233
  • 2
  • 9
  • 7
105
votes
4 answers

What is the real purpose of Base64 encoding?

Why do we have Base64 encoding? I am a beginner and I really don't understand why would you obfuscate the bytes into something else (unless it is encryption). In one of the books I read Base64 encoding is useful when binary transmission is not…
Jack
  • 7,433
  • 22
  • 63
  • 107
104
votes
7 answers

Is a slash ("/") equivalent to an encoded slash ("%2F") in the path portion of an HTTP URL

I have a site that treats / and %2F in the path portion (not the query string) of a URL differently. Is this a bad thing to do according to either the RFC or the real world? I ask because I keep running into little surprises with the web framework…
user85509
  • 36,612
  • 7
  • 33
  • 26