// 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;
}