StringUtil.uts 735 字节
Newer Older
taohebin@dcloud.io's avatar
taohebin@dcloud.io 已提交
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31
export class StringUtil {
	static trimString(pSrc : string, removed : string) : string {
		const pTrimChar = removed.charAt(0)
		let _ret = pSrc;
		if (_ret != null && _ret != "") {
			const _startPosi = _ret.charAt(0) == pTrimChar ? 1 : 0;
			const _count = _ret.length;
			const _endPosi = _ret.charAt(_count - 1) == pTrimChar ? _count - 1 : _count;
			_ret = _ret.substring(_startPosi, _endPosi);
		}
		return _ret;
	}

	static getInt(content : string) : number | null {
		try {
			return content.toInt();
		} catch (e : Exception) {
			return null;
		}
	}


	static getDouble(content : string) : number | null {
		try {
			return content.toDouble()
		} catch (e : Exception) {
			return null;
		}
	}

}