urban legends just won't go away!

From: Barry Caplan (bcaplan@i18n.com)
Date: Thu Jan 30 2003 - 01:01:23 EST

  • Next message: Aditya Gokhale: "Re: Suggestions in Unicode Indic FAQ"

    http://archive.devx.com/free/tips/tipview.asp?content_id=4151

    Who knew in this day and age flipping bits to change case is still publishable (this is from today!)

    Barry Caplan
    www.i18n.com
    Vendor Showcase: http://Showcase.i18n.com

    --------------------------------------------------------------

    Use Logical Bit Operations to Changing Character Case

    This is a simple example demonstrating my own personal method.

    // to lower case
      public char lower(int c)
      {
           return (char)((c >= 65 && c <= 90) ? c |= 0x20 : c);
      }

    //to upper case
      public char upper(int c)
      {
        return (char)((c >= 97 && c <=122) ? c ^= 0x20 : c);
      }
    /*
     If I would I could create a method for converting an entire
    string to lower, like this:
    */
      public String getLowerString(String s)
      {
         char[] c = s.toCharArray();
         char[] cres = new char[s.length()];
         for(int i=0;i<c.length;++i)
             cres[i] = lower(c[i]);
         return String.valueOf(cres);
      }
    /*
    even converting in capital:
    */
      public String capital(String s)
      {
         return
    String.valueOf(upper(s.toCharArray()[0])).concat(s.substring(1));
      }
    /* using it....*/
    public static void main(String args[])
      {
         x xx = new x();
         System.out.println(xx.getLowerString("LOWER: " + "FRAME"));
         System.out.println(xx.upper('f'));
         System.out.println(xx.capital("randomaccessfile"));
    }



    This archive was generated by hypermail 2.1.5 : Thu Jan 30 2003 - 01:33:16 EST