Kerberos/Cerberus

"Greek form: Κέρβερος, Cerberus was the son of Echidna, a hybrid half-woman, half-serpent and Typhon, a fire-breathing giant whom even the Olympian gods feared. Its brother is Orthrus, always depicted as a two-headed hellhound. The common depiction of Cerberus in Greek mythology and art is as having three heads, a mane of live serpents (similar to Medusa's hair) and a snake's tail. In most works the three-heads each respectively see and represent the past, the present, and the future, while other sources suggest the heads represent birth, youth, and old age. Each of Cerberus' heads is said to have an appetite only for live meat and thus allow the spirits of the dead to freely enter the underworld, but allow none to leave. Cerberus was always employed as Hades' loyal watchdog, and guarded the gates that granted access and exit to the underworld." Wikipedia

Wednesday, June 2, 2010

trim(), ltrim(), rtrim() [Javascript Implementation]


 rtrim, ltrimtrim are string manipulation functions
 which strip or remove whitespaces from the beginning, ending,
 or both beginning and ending of a string. 



  Code:

   function trim(id){
    var txt = document.getElementById(id);
    var str = txt.value.replace(/^\s+/, '').replace(/\s+$/, '');
    return str;
   }

   function ltrim(id){
    var txt = document.getElementById(id);
    var str = txt.value.replace(/^\s+/, '');
    return str;
   }

   function rtrim(id){
    var txt = document.getElementById(id);
    var str = txt.value.replace(/\s+$/, '');
    return str;
   }




See sample output below:
Input Text Here:

Output:


0 comment/s:

Post a Comment