Questions tagged [encode]

to convert some data (e.g. string, picture) to some representation (e.g. bytes, electrical signals, numbers)

3168 questions
2860
votes
22 answers

Encode URL in JavaScript

How do you safely encode a URL using JavaScript such that it can be put into a GET string? var myUrl = "http://example.com/index.html?param=1&anotherParam=2"; var myOtherUrl = "http://example.com/index.html?url=" + myUrl; I assume that you need to…
nickf
  • 537,072
  • 198
  • 649
  • 721
1013
votes
19 answers

What is base 64 encoding used for?

I've heard people talking about "base 64 encoding" here and there. What is it used for?
MrDatabase
  • 43,245
  • 41
  • 111
  • 153
378
votes
19 answers

Encoding as Base64 in Java

I need to encode some data in the Base64 encoding in Java. How do I do that? What is the name of the class that provides a Base64 encoder? I tried to use the sun.misc.BASE64Encoder class, without success. I have the following line of Java 7…
Jury A
  • 19,192
  • 24
  • 69
  • 93
194
votes
8 answers

How to convert a string or integer to binary in Ruby?

How do you create integers 0..9 and math operators + - * / in to binary strings. For example: 0 = 0000, 1 = 0001, ... 9 = 1001 Is there a way to do this with Ruby 1.8.6 without using a library?
mcmaloney
  • 2,374
  • 3
  • 19
  • 19
190
votes
6 answers

Strange \n in base64 encoded string in Ruby

The inbuilt Base64 library in Ruby is adding some '\n's. I'm unable to find out the reason. For this special example: irb(main):001:0> require 'rubygems' => true irb(main):002:0> require 'base64' => true irb(main):003:0> str = …
intellidiot
  • 11,108
  • 4
  • 34
  • 41
188
votes
6 answers

Convert int to ASCII and back in Python

I'm working on making a URL shortener for my site, and my current plan (I'm open to suggestions) is to use a node ID to generate the shortened URL. So, in theory, node 26 might be short.com/z, node 1 might be short.com/a, node 52 might be…
mlissner
  • 17,359
  • 18
  • 106
  • 169
188
votes
6 answers

UnicodeEncodeError: 'charmap' codec can't encode - character maps to , print function

I am writing a Python (Python 3.3) program to send some data to a webpage using POST method. Mostly for debugging process I am getting the page result and displaying it on the screen using print() function. The code is like…
187
votes
6 answers

Base64 Java encode and decode a string

I want to encode a string into base64 and transfer it through a socket and decode it back. But after decoding it gives different answer. Following is my code and result is "77+9x6s=" import javax.xml.bind.DatatypeConverter; public class f{ …
Sameera Kumarasingha
  • 2,908
  • 3
  • 25
  • 41
151
votes
3 answers

PHP "pretty print" json_encode

Possible Duplicate: Pretty-Printing JSON with PHP I'm working on a script that creates a JSON file. Right now I'm just using json_encode (PHP 5.2.x) to encode an array into JSON output. Then I print the returned value to a file and save it.…
Brian
  • 7,204
  • 12
  • 51
  • 84
124
votes
5 answers

Code for decoding/encoding a modified base64 URL (in ASP.NET Framework)

I want to base64 encode data to put it in a URL and then decode it within my HttpHandler. I have found that Base64 Encoding allows for a '/' character which will mess up my UriTemplate matching. Then I found that there is a concept of a "modified…
Kirk Liemohn
  • 7,733
  • 9
  • 46
  • 57
115
votes
9 answers

Python Unicode Encode Error

I'm reading and parsing an Amazon XML file and while the XML file shows a ' , when I try to print it I get the following error: 'ascii' codec can't encode character u'\u2019' in position 16: ordinal not in range(128) From what I've read online…
Alex B
  • 1,185
  • 2
  • 8
  • 5
113
votes
8 answers

How to set emoji by unicode in a textview?

Hi I'd like to do the following: ??? unicode = U+1F60A String emoji = getEmojiByUnicode(unicode) String text = "So happy " textview.setText(text + emoji); to get this in my textview: So happy How can I implement getEmojiByUnicode(unicode)? What…
Gilbert Giesbert
  • 3,338
  • 3
  • 13
  • 10
112
votes
6 answers

AJAX POST and Plus Sign ( + ) -- How to Encode?

I'm POSTing the contents of a form field via AJAX to a PHP script and using JavaScript to escape(field_contents). The problem is that any plus signs are being stripped out and replaced by spaces. How can I safely 'encode' the plus sign and then…
jalperin
  • 2,664
  • 9
  • 30
  • 32
110
votes
8 answers

How to HTML encode/escape a string? Is there a built-in?

I have an untrusted string that I want to show as text in an HTML page. I need to escape the chars '<' and '&' as HTML entities. The less fuss the better. I'm using UTF8 and don't need other entities for accented letters. Is there a built-in…
kch
  • 77,385
  • 46
  • 136
  • 148
74
votes
6 answers

JSON stringify missing from jQuery 1.4.1?

Apparently jQuery has the ability to decode a given object or string into a JSON object. However, I have a JS object that I need to POST back to the server and I find no utility in jQuery that wraps the JSON.stringify() function. That function is…
Geuis
  • 41,122
  • 56
  • 157
  • 219
1
2 3
99 100