JavaScript自定义函数实现字符串SubString
2017-05-30 13:24:37 访问(1670) 赞(0) 踩(0)
-
function StrTrim(str) {
// Trim + //
if (str == null)
return "";
return str.replace(/(^\s*)|(\s*$)/g, "");
}
function MathToInt(str, defaultValue) {
// 转Int数字 //
var theStr = StrTrim(str);
if (theStr == "")
return defaultValue;
if (theStr == "0")
return 0;
var theResult = parseInt(theStr, 10);
if (theResult == NaN || theResult == undefined)
return defaultValue;
return theResult;
}
function StrSubString(str, sIdx) {
if (str == null || str == "")
return "";
var startIndex = MathToInt(sIdx, null);
if (startIndex == 0)
return str;
if (startIndex == null) {
return "";
}
var theLen = str.length;
if (startIndex >= theLen)
return "";
return str.substr(startIndex, theLen);
}
-
上一条:
下一条:
相关评论
发表评论