Never been to DZone Snippets before?

Snippets is a public source code repository. Easily build up your personal collection of code snippets, categorize them with tags / keywords, and share them with the world

« Newer Snippets
Older Snippets »
Showing 21-23 of 23 total

Write your code using utf-8

   1  # -*- coding: utf-8 -*-


Add this line at the beginning of your code. Python won't complain anymore about non-ascii characters in your code.

Ellipsis in Unicode ("...")

Character 0x2026 is the ellipsis "..." (three dots):

Use it in java for Buttons, e.g: "Refresh...":

   1  
   2      private class RefreshAction extends AbstractAction {
   3  
   4          private RefreshAction() {
   5              super("Refresh\u2026");
   6          }
   7  
   8          public void actionPerformed(ActionEvent e) {
   9              ...
  10          }
  11      }


Or in HTML:
   1  
   2  …

Using utf-8 in python

Convert a byte string into a Unicode string and back again.
   1  
   2  s = "hello normal string"
   3  u = unicode(s, "utf-8")
   4  backToBytes = u.encode("utf-8")

For Thai, python uses cp874 encoding.
   1  
   2  s = ''    # my thai name
   3  t = s.decode('cp874')  # same as unicode(..)
   4  appuifw.note(t, 'info')
« Newer Snippets
Older Snippets »
Showing 21-23 of 23 total