zoukankan      html  css  js  c++  java
  • toLowerCase和toLocaleLowerCase的区别


    ECMAScript中涉及字符串大小写转换的方法有4个:toLowerCase()、toLocaleLowerCase()、toUpperCase()和toLocaleUpperCase()。
    其中,toLowerCase()和toUpperCase()是两个经典的方法,借鉴自java.lang.String中的同名方法。而toLocaleLowerCase()和toLocaleUpperCase()方法则是针对特定地区的实现。
    对有些地区来说,针对地区的方法与其通用方法得到的结果相同,但少数语言(如土耳其语言)会为Unicode大小写转换应用特殊的规则,这时候就必须使用针对地区的方法来保证实现正确的转换。以下是几个例子:
    var stringValue = "hello world";
    alert(stringValue.toLocaleUpperCase()); //"HELLO WORLD"
    alert(stringValue.toUpperCase()); //"HELLO WORLD"
    alert(stringValue.toLocaleLowerCase()); //"hello world"
    alert(stringValue.toLowerCase()); //"hello world"123456

    代码laycode - v1.1
    以上代码调用的toLocaleUpperCase()和toUpperCase()都返回了“HELLO WORLD”,就像调用toLocaleLowerCase()和toLowerCase()都返回“hello world”一样。一般来说,在不知道自己的代码将在那种语言环境中运行的情况下,还是使用针对地区的方法更稳妥一些。
  • 相关阅读:
    leetcode8.字符串转换整数(atoi)
    leetcode7、整数反转
    leetcode6.Z字形变换
    leetcode5.最长回文子串
    leetcode4.寻找两个正序数组的中位数
    leetcode3. 无重复字符的最长子串
    leetcode 2.两数相加
    leetcode 1. 两数之和
    post&get请求总结
    oracle知识总结
  • 原文地址:https://www.cnblogs.com/duenyang/p/5770797.html
Copyright © 2011-2022 走看看