Monday 21 January 2013

Parsing Strings in PL/SQL


Consider a scenario where you need to parse a VARCHAR2 value which is delimited by a special character such as a comma. Rather than parse the entire input and search for the start and end of each sub-string, use the apex_util.string_to_table() that is available in Oracle 10G and 11G

A typical usage example would be as follows:

DECLARE

variable_array_to_hold_values apex_application_global.vc_arr2;
variable_test VARCHAR2(100) := 'show:me:a:parser';

 BEGIN

    variable_array_to_hold_values := apex_util.string_to_table(variable_test, ':');
     FOR i IN 1..variable_array_to_hold_values.COUNT
     LOOP
         DBMS_OUTPUT.PUT_LINE(' Value is ' || variable_array_to_hold_values(i));
     END LOOP;
 END;
 /

And the result would be
 Value is show
 Value is me
 Value is a
 Value is parser

Thursday 17 January 2013

Apache Commons Lang Library : Managing Strings without NullPointers

The Apache Commons Lang 3.0 package is a useful set of utilities and interface definitions for String and Character manipulation. With respect to String manipulation, the StringUtils, StringEscapeUtils, RandomStringUtils, Tokenizer, WordUtils classes provide a number of utility methods for manipulating and managing String.

The StringUtils class has some interesting functions such as 
  • IsEmpty/IsBlank - checks if a String contains text. The main difference between IsEmpty and IsBlank is that that IsBlank also checks for whitespaces while IsEmpty doesn't. 
  • Trim/Strip - removes leading and trailing whitespace
  • Equals - compares two strings null-safe
  • startsWith - check if a String starts with a prefix null-safe
  • endsWith - check if a String ends with a suffix null-safe
  • IndexOf/LastIndexOf/Contains - null-safe index-of checks
  • IndexOfAny/LastIndexOfAny/IndexOfAnyBut/LastIndexOfAnyBut - index-of any of a set of Strings
  • ContainsOnly/ContainsNone/ContainsAny - does String contains only/none/any of these characters
  • Substring/Left/Right/Mid - null-safe substring extractions
  • SubstringBefore/SubstringAfter/SubstringBetween - substring extraction relative to other strings
  • Split/Join - splits a String into an array of substrings and vice versa
While these functions may appear similar to the ones provided by the String package itself, the StringUtils versions are null safe thus eliminating the possiblity of those horrible NPEs. It should be noted that a null input will return null without throwing any exception.

Saturday 12 January 2013

The Kogan Agora 10 inch Tablet : A user review

Recently purchased a two month old Kogan Agora Tablet powered by a 1, GHz single-core ARM Cortex A8, running an Android 4.0.4 ICS. It has 16 GB storage expandable to 32 GB, a sleek 10 inch screen with a 1024x768  LCD display, weighs 600gms  and is about 12 mm thick. Priced at less than $200 ( I got it for less than $150 off eBay), it is an excellent entry level device into the world of tablet computing. 
My requirements were modest at best. I needed a tablet that could play some kiddie games for my 2 year old, browse the net and handle some rough treatment at the hands of my 2 year old. Suffice to say the tablet so far meets all my requirements.
On the plus side, it has a sleek look, is light and easy to hold and use. The pinch and zoom feature that has been maligned in several reviews, worked well for me. Simple games like Talking Tom work well and give an indication of how well the microphone and the speakers work. 
On the negative side, the twin cameras produce disappointing results as compared to the photos taken by the Samsung tablets and multi-tasking is definitely not one of the tablet's strong features. Even loading two sites at the same time can make the device slow and unresponsive but with the latest models offering a dual core processor this problem could well be a thing of the past.
Even with its relative slow performance, if I went back and evaluated it against my original requirement of acquiring an entry level tablet device which is fully functional, it is a great buy and yes I won't feel bad at all if my 2 year old accidentally breaks it.
Finally, a handy tip, get yourself a leather case and a screen protector if you intend to share the device with your kids and if still unsure have a read of this review  and perhaps this one (for more technical comparisons) from June 2012, which benchmarks the Tablet running Android 4.0.3 ICS (the previous version to the one I have installed).