|
 |
17³â Àü |
// HTML Ư¼ö¹®ÀÚ¸¦ º¯È¯ÇÔ¼ö
String.prototype.htmlChars = function () {
var str = ((this.replace('"', '&')).replace('"', '"')).replace('\'', ''');
return (str.replace('<', '<')).replace('>', '>');
}
// ÁÂ¿ì °ø¹é¾ø¾Ö´Â ÇÔ¼ö
String.prototype.trim = function () { return this.replace(/(^s*)|(s*$)/g, ""); }
// ¿ÞÂÊ °ø¹é¾ø¾Ö´Â ÇÔ¼ö
String.prototype.ltrim = function () { return this.replace(/^s*/g, ""); }
// ¿À¸¥ÂÊ °ø¹é¾ø¾Ö´Â ÇÔ¼ö
String.prototype.rtrim = function () { return this.replace(/s*$/g, ""); }
// ű׸¸ Á¦°ÅÇÔ¼ö
String.prototype.stripTags = function () {
var str = this;
var pos1 = str.indexOf('<');
if (pos1 == -1) return str;
else {
var pos2 = str.indexOf('>', pos1);
if (pos2 == -1) return str;
return (str.substr(0, pos1) + str.substr(pos2+1)).stripTags();
}
}
// ´ë¼Ò¹®ÀÚ ±¸º°ÇÏÁö ¾Ê°í ´Ü¾î À§Ä¡ ã±âÇÔ¼ö
// needle:°Ë»ö´Ü¾î, offset:°Ë»ö½ÃÀÛÀ§Ä¡ , ÇØ´ç´Ü¾î°¡ ¾øÀ»½Ã -1¸®ÅÏ
String.prototype.ipos = function (needle, offset) {
var offset = (typeof offset == "number")?offset:0;
return this.toLowerCase().indexOf(needle.toLowerCase(), offset);
}
// ´ë¼Ò¹®ÀÚ ±¸º°ÇÏÁö ¾Ê°í µÚ¿¡¼ºÎÅÍ ´Ü¾îÀ§Ä¡ ã±âÇÔ¼ö
String.prototype.ripos = function (needle, offset) {
var offset = (typeof offset == "number")?offset:0;
return this.toLowerCase().lastIndexOf(needle.toLowerCase(), offset);
}
// ¹®ÀÚ¿À» ¹è¿·Î º¯È¯ÇÏ´Â ÇÔ¼ö
String.prototype.toArray = function () {
var len = this.length;
var arr = new Array;
for (var i=0; i<len; i++) arr[i] = this.charAt(i);
return arr;
}
#»ç¿ë¹æ¹ý
test = "<td>";
a= test.htmlChars(); // a="<td>";
a= test.ipos('t',0) // a=1 , offset=2 -> a=-1
a= test.toArray(); //a[0]='<', a[1]='t', a[2]='d', a[3]='>' |
|
̵̧ : 313 |
̵̧
¸ñ·Ï
|
|