Javascript count line breaks
function lineBreakCount(str){ /* counts \n */ try { return((str.match(/[^\n]*\n[^\n]*/gi).length)); } catch(e) { return 0; } }
12389 users tagging and storing useful source code snippets
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
Jochen Preusche http://www.jochenpreusche.de
function lineBreakCount(str){ /* counts \n */ try { return((str.match(/[^\n]*\n[^\n]*/gi).length)); } catch(e) { return 0; } }
function money2int(m){ var pattern = /[\.,][-|–]?$/; /* 100.-- >>> 100 */ /* 100,- >>> 100 */ var m = m.replace(pattern, ""); var pattern = /[\.,]([\d]{0,2})$/; /* 100,95 >>> 100X95 */ var m = m.replace(pattern, "X$1"); var pattern = /[\.',]/g; /* delete ' , . */ var m = m.replace(pattern, ""); var m = m.replace(/X/g, '.'); /* 100X95 >> 100.95 */ if(isNaN(m*1)) return false; return(m*1); }
cmpDat = new Array(2007, 12, 2, 0, 0, 0); /* year mon day hr min sec */ function compareDates(cmpDat){ var jd:Date = new Date(); var zd:Date = new Date(cmpDat[0], cmpDat[1]-1, cmpDat[2], cmpDat[3], cmpDat[4], cmpDat[5], 0); if(zd.getTime()<jd.getTime()){ return true; } else { return false; } } // the time is now? (true / false) if(compareDates(cmpDat)){ trace('ok das wars dann'); }
function getparams(s){ a = s.match(/[^&?=]*=[^&?=]*/g); r = new Array(); for (i=0; i<a.length; i++) { r[i] = new Array(a[i].match(/[^&?=]*/)[0], a[i].match(/=([^&?]*)/)[0].replace('=', '')); } return(r); }
function getvars(s){ // php preg_match would be as easy as: (/([^&?=])=[^&?=]/g) a = s.match(/[^&?=]*=[^&?=]*/g); r = new Array(); for (i=0; i<a.length; i++) { r[i] = a[i].match(/[^&?=]*/)[0]; } return(r); } /* test */ alert(getvars(window.location.search));
/* javascript */ String.prototype.get = function(p){ return(this.match(new RegExp("[?|&]?" + p + "=([^&]*)"))[1]); } /* test: yourfile.html?test=test234 alerts: test234 */ alert(window.location.search.get('test'));