JavaScript中操作字符串之localeCompare()方法的使用


这个方法返回一个数字表示参考字符串是否到来之前或之后或相同的排序顺序给定的字符串。
语法

string.localeCompare( param )

下面是参数的详细信息:

param : 字符串对象进行比较的字符串

返回值:

0 : 字符串匹配100% 1 : 不匹配,参数值来自于语言环境的排序顺序字符串对象的值之前 -1 : 不匹配,参数值来自于语言环境的排序顺序字符串对象的值之后

例子:

<html>
<head>
<title>JavaScript String localeCompare() Method</title>
</head>
<body>
<script type="text/javascript">
var str1 = new String( "This is beautiful string" );
var index = str1.localeCompare( "XYZ" );
document.write("localeCompare first :" + index ); 

document.write("<br />" ); 

var index = str1.localeCompare( "AbCD ?" );
document.write("localeCompare second :" + index ); 

</script>
</body>
</html>

这将产生以下结果:

localeCompare first :-1
localeCompare second :1 

JavaScript中String.match()方法的使用详解
此方法用于当匹配针对正则表达式的字符串来检索匹配。语法string.match(param)下面是参数的详细信息:param:正则表达式对象返回值:如果正则表达式不包括

JavaScript中的replace()方法使用详解
该方法找到一个正则表达式的字符串之间的匹配,并取代了匹配的子带的新的子串。替换字符串可以包含以下特殊替换模式:语法string.replace(regexp/substr,

简介JavaScript中search()方法的使用
此方法执行搜索正则表达式,String对象之间的匹配。语法string.search(regexp);下面是参数的详细信息:regexp:正则表达式对象。如果非RegExp对象obj传递,它是