In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-17 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >
Share
Shulou(Shulou.com)05/31 Report--
This article mainly introduces the relevant knowledge of "how to deal with classes with javascript strings". The editor shows you the operation process through an actual case. The operation method is simple, fast and practical. I hope this article "how to deal with classes with javascript strings" can help you solve the problem.
/ / =
/ / function: remove the spaces on both sides of the string
/ / return: true-contains this illegal character false-does not contain
Function TrimString (str)
{
Var i,j
If (str = "") return ""
For (iTuno _ str.length) return ""
For (jroomstr.roomthmurl _ 1 ~ j > = 0 _ Ted _ jmuri -)
If (str.charAt (j)! ='') break
Return str.substring (iMagne jungle 1)
}
/ / =
/ / function: check whether it exists "
< >Special characters such as "'& /; |"
/ / return: true-contains this illegal character false-does not contain
Function CheckSpecialChar (strSource)
{
Var intIndex =-1; / / this character was not found, return-1
Var regExpInfo = / & /
IntIndex = strSource.search (regExpInfo)
If (intIndex =-1)
{
RegExpInfo = / intIndex = strSource.search (regExpInfo)
}
If (intIndex =-1)
{
RegExpInfo = / > /
IntIndex = strSource.search (regExpInfo)
}
If (intIndex =-1)
{
RegExpInfo = / "/
IntIndex = strSource.search (regExpInfo)
}
If (intIndex =-1)
{
RegExpInfo = /'/
IntIndex = strSource.search (regExpInfo)
}
If (intIndex =-1)
{
RegExpInfo = /; /
IntIndex = strSource.search (regExpInfo)
}
/ / if (intIndex = =-1)
/ / {
/ / regExpInfo = / | /
/ / intIndex = strSource.search (regExpInfo)
/ /}
If (intIndex =-1)
{
RegExpInfo = /
IntIndex = strSource.search (regExpInfo)
}
If (intIndex =-1)
{
RegExpInfo = / /
IntIndex = strSource.search (regExpInfo)
}
If (intIndex =-1)
{
Return false
}
Else
{
Return true
}
}
/ / =
/ / function: using regular expressions, in a string, for special characters:'"
< >& encode
/ / Parameter: strSource-the source string to be replaced
/ / return: encoded string
Function EncodeSpecialChar (strSource)
{
Var stEncodeResult = strSource
/ / empty string
If (stEncodeResult = "")
{
Return stEncodeResult
}
/ / replace the "&" character in the string with "&"
/ / when replacing, you must first replace the "&" character, otherwise, "will be replaced with". "
RegExpInfo= / > / g
StEncodeResult = stEncodeResult.replace (regExpInfo, ")
/ / replace% with "%"
RegExpInfo= /% / g
StEncodeResult = stEncodeResult.replace (regExpInfo, "%")
Return stEncodeResult
}
/ / =
/ / function: remove the spaces before and after the string
/ / Parameter: source string
Function RemoveBrank (strSource)
{
Var strArm = ""
If (strSource.length
< 1) return strArm; strArm = RemoveForwardBrank(strSource); //去掉字符串前面所有的空格 strArm = RemoveBehindBrank(strArm); //去掉字符串后面所有的空格 return strArm; } //======================================================================== //功能:去掉字符串前面所有的空格 //参数:源字符串 //返回:去掉源字符串前面空格后的字符串 function RemoveForwardBrank(strSource) { var strArm = ""; for(var i = 0;i < strSource.length;i ++) { if(strSource.charAt(i) != " ") { strArm = strSource.substring(i,strSource.length); break; } } return strArm; } //======================================================================== //功能:去掉字符串后面所有的空格 //参数:源字符串 //返回:去掉源字符串后面空格后的字符串 function RemoveBehindBrank(strSource) { var strArm = ""; var intLength = strSource.length; var intCount = 0; while(intLength --) { if(strSource.charAt(intLength) == " ") intCount ++; else break; } strArm = strSource.substring(0,strSource.length - intCount); return strArm; } //======================================================================== //功能:判断一个数是否为正整数 //参数:strNum ---- 需要判断的字符串 //返回:true ---- 整数 // false ---- 非整数 function IsIntNum(strNum) { var strCheckNum = strNum + ""; if(strCheckNum.length < 1) //空字符串 return false; else if(isNaN(strCheckNum)) //不是数值 return false; else if(parseInt(strCheckNum) < 1) //不是正数 return false; else if(parseFloat(strCheckNum) >ParseInt (strCheckNum)) / / is not an integer
Return false
Return true
}
/ / =
/ / function: judge whether a number is positive or not
/ / Parameter: strNum-the string to be judged
/ / return: true-integer
/ / false-non-integer
Function IsTrueNum (strNum)
{
Var strCheckNum = strNum + ""
If (strCheckNum.length < 1) / / empty string
Return false
Else if (isNaN (strCheckNum)) / / is not a numerical value
Return false
Else if (parseInt (strCheckNum) < 1) / / is not a positive number
Return false
Return true
}
This is the end of the introduction to "how javascript strings deal with classes". Thank you for reading. If you want to know more about the industry, you can follow the industry information channel. The editor will update different knowledge points for you every day.
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.