无为清净楼资源网 Design By www.qnjia.com
核心代码:
复制代码 代码如下:
/**
* jscript.string package
* This package contains utility functions for working with strings.
*/
if (typeof jscript == 'undefined') {
jscript = function() { }
}
jscript.string = function() { }
/**
* This function searches a string for another string and returns a count
* of how many times the second string appears in the first.
*(返回字符串中某子串出现的次数)
* @param inStr The string to be searched.
* @param inSearchStr The string to search for.
* @return The number of times inSearchStr appears in inStr,
* or 0 if inStr or inSearchStr is null or a blank string.
*/
jscript.string.substrCount = function(inStr, inSearchStr) {
if (inStr == null || inStr == "" ||
inSearchStr == null || inSearchStr == "") {
return 0;
}
var splitChars = inStr.split(inSearchStr);
return splitChars.length - 1;
} // End substrCount().
/**
* This function will take take an input string and either strip any
* character that appears in a given list of characters, or will strip any
* character that does NOT appear in a given list of characters.
*(此函数用来屏蔽或者保留 "inCharList" 中的字符,取决于参数 "inStripOrAllow")
* @param inStr The string to strip characters.
* @param inStripOrAllow Either the value "strip" or "allow".
* @param inCharList This is either (a) the list of characters that
* will be stripped from inStr (when inStripOrAllow ==
* "strip"), or (b) the list of characters that will
* NOT be stripped from inStr (when inStripOrAllow ==
"allow".
* @return The value of inStr after characters have been
* stripped as specified.
*/
jscript.string.stripChars = function(inStr, inStripOrAllow, inCharList) {
if (inStr == null || inStr == "" ||
inCharList == null || inCharList == "" ||
inStripOrAllow == null || inStripOrAllow == "") {
return "";
}
inStripOrAllow = inStripOrAllow.toLowerCase();
var outStr = "";
var i;
var j;
var nextChar;
var keepChar;
for (i = 0; i < inStr.length; i++) {
nextChar = inStr.substr(i, 1);
if (inStripOrAllow == "allow") {
keepChar = false;
} else {
keepChar = true;
}
for (j = 0; j < inCharList.length; j++) {
checkChar = inCharList.substr(j, 1);
if (inStripOrAllow == "allow" && nextChar == checkChar) {
keepChar = true;
}
if (inStripOrAllow == "strip" && nextChar == checkChar) {
keepChar = false;
}
}
if (keepChar == true) {
outStr = outStr + nextChar;
}
}
return outStr;
} // End stripChars().
/**
* This function can check is a given string either only contains characters
* from a list, or does not contain any characters from a given list.
*(此函数用来判断 inString 是否为 inCharList 中的字符,或者进行相反的判断,取决于参数 inFromExcept)
* @param inString The string to validate.
* @param inCharList A list of characters that is either (a) the only
* characters allowed in inString (when inFromExcept
* is == "from_list") or (b) the only characters that
* cannot appear in inString (when inFromExcept is
* == "not_from_list").
* @param inFromExcept When this is "from_list", then inString may only
* contain characters from inCharList. When this is
* "not_from_list", then inString can contain any character
* except thos in inCharList.
* @return True if inString only contains valid characters,
* as listed in inCharList when inFromExcept ==
* "from_list", false if not, or true if inString does
* not containt any of the characters listed in
* inCharList when inFromExcept == "not_from_list".
*/
jscript.string.strContentValid = function(inString, inCharList, inFromExcept) {
if (inString == null || inCharList == null || inFromExcept == null ||
inString == "" || inCharList == "") {
return false;
}
inFromExcept = inFromExcept.toLowerCase();
var i;
if (inFromExcept == "from_list") {
for (i = 0; i < inString.length; i++) {
if (inCharList.indexOf(inString.charAt(i)) == -1) {
return false;
}
}
return true;
}
if (inFromExcept == "not_from_list") {
for (i = 0; i < inString.length; i++) {
if (inCharList.indexOf(inString.charAt(i)) != -1) {
return false;
}
}
return true;
}
} // End strContentValid().
/**
* This function replaces a given substring of a string (all occurances of
* it to be more precise) with a specified new substring. The substrings
* can of course be single characters.
*(此函数进行字符串的替换功能,将 inSrc 中的 inOld 全部替换为 inNew)
* @param inSrc The string to replace substring(s) in.
* @param inOld The substring to replace.
* @param inNew The new substring to insert.
* @return The value of inSrc with all occurances of inOld replaced
* with inNew.
*/
jscript.string.replace = function(inSrc, inOld, inNew) {
if (inSrc == null || inSrc == "" || inOld == null || inOld == "" ||
inNew == null || inNew == "") {
return "";
}
while (inSrc.indexOf(inOld) > -1) {
inSrc = inSrc.replace(inOld, inNew);
}
return inSrc;
} // End replace().
/**
* Function to trim whitespace from the beginning of a string.
*(从字符串的左面开始去除空白字符)
* @param inStr The string to trim.
* @return The trimmed string, or null if null or a blank string was
* passed in.
*/
jscript.string.leftTrim = function(inStr) {
if (inStr == null || inStr == "") {
return null;
}
var j;
for (j = 0; inStr.charAt(j) == " "; j++) { }
return inStr.substring(j, inStr.length);
} // End leftTrim().
/**
* Function to trim whitespace from the end of a string.
*(与上面的函数相对应,从字符串的右侧去除空白字符)
* @param inStr The string to trim.
* @return The trimmed string, or null if null or a blank string was
* passed in.
*/
jscript.string.rightTrim = function(inStr) {
if (inStr == null || inStr == "") {
return null;
}
var j;
for (j = inStr.length - 1; inStr.charAt(j) == " "; j--) { }
return inStr.substring(0, j + 1);
} // End rightTrim().
/**
* Function to trim whitespace from both ends of a string.
*
* @param inStr The string to trim.
* @return The trimmed string, or null if null or a blank string was
* passed in.
*/
jscript.string.fullTrim = function(inStr) {
if (inStr == null || inStr == "") {
return "";
}
inStr = this.leftTrim(inStr);
inStr = this.rightTrim(inStr);
return inStr;
} // End fullTrim().

演示区:

[Ctrl+A 全选 注:引入外部Js需再刷新一下页面才能执行]
标签:
String,字符串

无为清净楼资源网 Design By www.qnjia.com
广告合作:本站广告合作请联系QQ:858582 申请时备注:广告合作(否则不回)
免责声明:本站文章均来自网站采集或用户投稿,网站不提供任何软件下载或自行开发的软件! 如有用户或公司发现本站内容信息存在侵权行为,请邮件告知! 858582#qq.com
无为清净楼资源网 Design By www.qnjia.com

《魔兽世界》大逃杀!60人新游玩模式《强袭风暴》3月21日上线

暴雪近日发布了《魔兽世界》10.2.6 更新内容,新游玩模式《强袭风暴》即将于3月21 日在亚服上线,届时玩家将前往阿拉希高地展开一场 60 人大逃杀对战。

艾泽拉斯的冒险者已经征服了艾泽拉斯的大地及遥远的彼岸。他们在对抗世界上最致命的敌人时展现出过人的手腕,并且成功阻止终结宇宙等级的威胁。当他们在为即将于《魔兽世界》资料片《地心之战》中来袭的萨拉塔斯势力做战斗准备时,他们还需要在熟悉的阿拉希高地面对一个全新的敌人──那就是彼此。在《巨龙崛起》10.2.6 更新的《强袭风暴》中,玩家将会进入一个全新的海盗主题大逃杀式限时活动,其中包含极高的风险和史诗级的奖励。

《强袭风暴》不是普通的战场,作为一个独立于主游戏之外的活动,玩家可以用大逃杀的风格来体验《魔兽世界》,不分职业、不分装备(除了你在赛局中捡到的),光是技巧和战略的强弱之分就能决定出谁才是能坚持到最后的赢家。本次活动将会开放单人和双人模式,玩家在加入海盗主题的预赛大厅区域前,可以从强袭风暴角色画面新增好友。游玩游戏将可以累计名望轨迹,《巨龙崛起》和《魔兽世界:巫妖王之怒 经典版》的玩家都可以获得奖励。