• λ我爱Aspx >> Asp.Net >> 用 JavaScript 操作字符串
  • 用 JavaScript 操作字符串

  • :未知  Դ:internet  :2007-5-20 16:44:28  ؼ:javascript
  • ? toUpperCase() – 将整个字符串转成大写字母。

    注意: concat 、 match 、 replace 和 search 函数是在 JavaScript 1.2 中加入的。所有其它函数在 JavaScript 1.0 就已经提供了。

    下面让我们看一下如何在 JavaScript 使用这些函数。下面的代码是用到了前面提到的所有函数:

    function manipulateString(passedString1, passedString2) {

    var concatString;

    // The string passed to concat is added to the end of the first string

    concatString = passedString1.concat(passedString2);

    alert(concatString);

    // The following if statement will be true since first word is Tony

    if (concatString.charAt(3) == "y") {

    alert("Character found!");

    }

    // The last position of the letter n is 10

    alert("The last index of n is: " + concatString.lastIndexOf("n"));

    // A regular expression is used to locate and replace the substring

    var newString = concatString.replace(/Tony/gi,"General");

    // The following yields Please salute General Patton

    Ҷƪл˵?
  • һƪJavascript里的类构造
    һƪJavaScript中this关键字使用方法详解