Strange \n in base64 encoded string in Ruby

Edit: Since I wrote this answer Base64.strict_encode64() was added, which does not add newlines. The docs are somewhat confusing, the b64encode method is supposed to add a newline for every 60th character, and the example for the encode64 method is actually using the b64encode method. It seems the pack(“m”) method for the Array class used … Read more

PHP unserialize fails with non-encoded characters?

The reason why unserialize() fails with: $ser=”a:2:{i:0;s:5:”héllö”;i:1;s:5:”wörld”;}”; Is because the length for héllö and wörld are wrong, since PHP doesn’t correctly handle multi-byte strings natively: echo strlen(‘héllö’); // 7 echo strlen(‘wörld’); // 6 However if you try to unserialize() the following correct string: $ser=”a:2:{i:0;s:7:”héllö”;i:1;s:6:”wörld”;}”; echo ‘<pre>’; print_r(unserialize($ser)); echo ‘</pre>’; It works: Array ( [0] => … Read more

C# Base64 String to JPEG Image

First, convert the base 64 string to an Image, then use the Image.Save method. To convert from base 64 string to Image: public Image Base64ToImage(string base64String) { // Convert base 64 string to byte[] byte[] imageBytes = Convert.FromBase64String(base64String); // Convert byte[] to Image using (var ms = new MemoryStream(imageBytes, 0, imageBytes.Length)) { Image image = … Read more

How to set emoji by unicode in a textview?

Found a solution: In my unicode I replaced ‘U+‘ by ‘0x‘ Example: replace ‘U+1F60A‘ by ‘0x1F60A‘ This way I got an ‘int’ like int unicode = 0x1F60A; Which can be used with public String getEmojiByUnicode(int unicode){ return new String(Character.toChars(unicode)); } So Textview displays 😊 without Drawable Try it with http://apps.timwhitlock.info/emoji/tables/unicode

Python & MySql: Unicode and Encoding

I think that your MYSQLdb python library doesn’t know it’s supposed to encode to utf8, and is encoding to the default python system-defined charset latin1. When you connect() to your database, pass the charset=”utf8″ parameter. This should also make a manual SET NAMES or SET character_set_client unnecessary.

Base64 Java encode and decode a string [duplicate]

You can use following approach: import org.apache.commons.codec.binary.Base64; // Encode data on your side using BASE64 byte[] bytesEncoded = Base64.encodeBase64(str.getBytes()); System.out.println(“encoded value is ” + new String(bytesEncoded)); // Decode data on other side, by processing encoded data byte[] valueDecoded = Base64.decodeBase64(bytesEncoded); System.out.println(“Decoded value is ” + new String(valueDecoded)); Hope this answers your doubt.