﻿/**
 * 去除首尾空格
 * @id String.prototype.trim
 * @author Burchin
 */
String.prototype.trim = function() {
	return this.replace(/(^\s*)|(\s*$)/g, "");
};

/**
 * 去除左边空格
 * @id String.prototype.lTrim
 * @author Burchin
 */
String.prototype.lTrim = function() {
	return this.replace(/(^\s*)/g, "");
};

/**
 * 去除右边空格
 * @id String.prototype.rTrim
 * @author Burchin
 */
String.prototype.rTrim = function() {
	return this.replace(/(\s*$)/g, "");
};

/**
 * 去除首尾空格和内部多余空格
 * @id String.prototype.clean
 * @author K
 */
String.prototype.clean = function() {
	return this.replace(/\s{2,}/g, ' ').trim();
}

/**
 * 获取字符串的字节长度
 * @id String.prototype.getRealLength
 * @author Burchin
 */
String.prototype.getRealLength = function() {
	return this.replace(/[^\x00-\xff]/g, "--").length;
};

/**
 * 从左边截取字符串
 * @id String.prototype.left
 * @author Burchin
 * @param {Object} p_length 指定截取的长度
 */
String.prototype.left = function(p_length) {
	return this.slice(0, p_length);
};

/**
 * 从右边截取字符串
 * @id String.prototype.right
 * @author Burchin
 * @param {Object} p_length 指定截取的长度
 */
String.prototype.right = function(p_length) {
	return this.slice(this.length - p_length);
};

/**
 * 替换&号和+号
 * @id String.prototype.noharmcode
 * @author K
 * @param 
 */
String.prototype.noharmcode= function () {
	return this.replace(/&/g, "%26").replace(/\+/g, "%2b");
}
