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
85
votes
3 answers

Usage of unicode() and encode() functions in Python

I have a problem with encoding of the path variable and inserting it to the SQLite database. I tried to solve it with encode("utf-8") function which didn't help. Then I used unicode() function which gives me type unicode. print type(path) …
xralf
  • 3,312
  • 45
  • 129
  • 200
84
votes
9 answers

Convert a Unicode string to an escaped ASCII string

How can I convert this string: This string contains the Unicode character Pi(π) into an escaped ASCII string: This string contains the Unicode character Pi(\u03a0) and vice versa? The current Encoding available in C# converts the π character to…
Ali
  • 1,503
  • 2
  • 15
  • 20
83
votes
10 answers

How to convert a file to utf-8 in Python?

I need to convert a bunch of files to utf-8 in Python, and I have trouble with the "converting the file" part. I'd like to do the equivalent of: iconv -t utf-8 $file > converted/$file # this is shell code Thanks!
Sébastien RoccaSerra
  • 16,731
  • 8
  • 50
  • 54
81
votes
1 answer

Python decoding Unicode is not supported

I am having a problem with my encoding in Python. I have tried different methods but I can't seem to find the best way to encode my output to UTF-8. This is what I am trying to do: result = unicode(google.searchGoogle(param),…
simonbs
  • 7,932
  • 13
  • 69
  • 115
81
votes
5 answers

JVM property -Dfile.encoding=UTF8 or UTF-8?

I would like to know what is the value of the Java Virtual Machine (JVM) property to set my file encoding to UTF-8. Do I put -Dfile.encoding=UTF8 or -Dfile.encoding=UTF-8?
twopheek
  • 1,035
  • 2
  • 8
  • 10
81
votes
9 answers

How to detect the character encoding of a text file?

I try to detect which character encoding is used in my file. I try with this code to get the standard encoding public static Encoding GetFileEncoding(string srcFile) { // *** Use Default of Encoding.Default (Ansi CodePage) Encoding…
Cédric Boivin
  • 10,854
  • 13
  • 57
  • 98
81
votes
16 answers

How can I URL encode a string in Excel VBA?

Is there a built-in way to URL encode a string in Excel VBA or do I need to hand roll this functionality?
Matthew Murdoch
  • 30,874
  • 30
  • 96
  • 127
80
votes
3 answers

is there a way to highlight all the special accent characters in sublime text or any other text editor?

I a using the the HTML encode special characters in Sublime text to convert all the special character into their HTML code. I have a lot of accented characters in different parts of the file. So, it would be great if I could select all the special…
kashive
  • 1,356
  • 2
  • 11
  • 17
79
votes
12 answers

"Unmappable character for encoding UTF-8" error

I'm getting a compile error at the following method. public static boolean isValidPasswd(String passwd) { String reg = "^(?=.*[0-9])(?=.*[a-z])(?=.*[A-Z])(?=.*[~#;:?/@&!\"'%*=¬.,-])(?=[^\\s]+$).{8,24}$"; return Pattern.matches(reg,…
Ravi
  • 7,939
  • 14
  • 40
  • 43
79
votes
5 answers

How to setup Visual Studio Code to detect and set the correct encoding on file open

I recently started to use Visual Studio Code on Server Systems where I did not have Studio IDE installed. I like it very much but I'm running into a problem. When I open a file (used Notepad++ before) the editor detects the encoding and sets it for…
YvesR
  • 5,922
  • 6
  • 43
  • 70
79
votes
15 answers

proper/best type for storing latitude and longitude

In a system level programming language like C, C++ or D, what is the best type/encoding for storing latitude and longitude? The options I see are: IEEE-754 FP as degrees or radians degrees or radians stored as a fixed point value in an 32 or 64 bit…
BCS
  • 75,627
  • 68
  • 187
  • 294
79
votes
20 answers

Short rot13 function - Python

I am searching for a short and cool rot13 function in Python ;-) I've written this function: def rot13(s): chars = "abcdefghijklmnopqrstuvwxyz" trans = chars[13:]+chars[:13] rot_char = lambda c: trans[chars.find(c)] if chars.find(c)>-1…
svenwltr
  • 17,002
  • 12
  • 56
  • 68
77
votes
3 answers

Base64 encoded string to file

I have a base64 encoded string. How can I write this base64 encoded string to a file?
JL.
  • 78,954
  • 126
  • 311
  • 459
77
votes
6 answers

How can I get a hex dump of a string in PHP?

I'm investigating encodings in PHP5. Is there some way to get a raw hex dump of a string? i.e. a hex representation of each of the bytes (not characters) in a string?
Amandasaurus
  • 58,203
  • 71
  • 188
  • 248
75
votes
14 answers

How do you remove invalid hexadecimal characters from an XML-based data source prior to constructing an XmlReader or XPathDocument that uses the data?

Is there any easy/general way to clean an XML based data source prior to using it in an XmlReader so that I can gracefully consume XML data that is non-conformant to the hexadecimal character restrictions placed on XML? Note: The solution needs to…
Oppositional
  • 11,141
  • 6
  • 50
  • 63