??javascript??java?е??????
???????????? ???????[ 2015/5/29 14:17:04 ] ????????Java
????javascript?????????
?????????????????
?????????????????м????????
????1????????????????????????????? var myStr = "Hello?? String!";// ??js?е?????????????
????2??????????????var myStr1 = new String("Hello?? String!");
????console.log(typeof myStr);//"string"
????console.log(typeof myStr1);//"object"
????????????????????myStr????????????????myStr1?????????
?????????????"????“????
????1????????????
????concat()????“+”
????2???????????
????1??string.substring(from?? to) ?????????????
???????????????????β????λ?á????????to??????????????С???????from??λ??????????????????????
????var str = "colin is a desinger";
????section = str .substring(0?? 4); // "coli"
????section = str .substring(4?? 0); // "coli"
????section = str .substring(1?? 1); // ""
????section = str .substring(-2?? 4); // "coli"
????str .substring(0?? 4);// "coli"<br>console.log(str) //"colin is a desinger";
????2??string.slice(start?? end) ?????????????
????????start???????????λ??????????????????????????????????????????-3???????????????????????end???????λ?????start? ???? ???????????????京???????????????????????slice()???????????????????????substring()??????????????????????? start??end?????????????????????
????var str = "colin is a desinger";
????section = str .slice(0?? 4); // "coli"
????section = str .slice(4?? -1); // "n is a desinge"
????section = str .slice(1?? 1); // ""
????str .slice(0?? 4);// ""
????console.log(str);//"colin is a desinger"
????3??substr(start??len) ?????????????
????????start??????λ???len????????????? ?????????ú???(??????????????)
???????????????“λ??”????
????1??str.indexOf(searchvalue??fromindex) ?????????????????????????????????????????????????????????????? -1 ??
????2??str.charAt(index) ???????λ??????
????3??str.charCodeAt(index) ???????λ???????? Unicode ?????????????? 0 - 65535 ??????????
????4??str.fromCharCode(numX??numX??...??numX) ????????????? Unicode ??????????????????
??????????????“????”????
????1?????????js?????????--> str.replace(regexp/substr??replacement)
?????????????????????????Щ????滻???Щ????????滻?????????????????????
???????? replacement?????????????????replace???????????????$??
????$i (i:1-99) : ?????????????????????????????
????$&:??????????????????????
????$`(`:?л??????)???????????????????????
????$’(‘:??????)???????????????????????
????$$?????$????
????"boy & girl".replace(/(w+)s*&s*(w+)/g??"$2 & $1") //girl & boy
????"boy".replace(/w+/g??"$&-$&") // boy-boy
????"javascript".replace(/script/??"$& != $`") //javascript != java
????"javascript".replace(/java/??"$&$' is ") // javascript is script
????????????????????
??????ECMAScript3?????ú?????????????JavaScript1.2.??replace??????е??????ζ??????ú??????????????滻???????
??????????????漲??
???????????????????????????$&????
?????м????????????????????????????.( $i (i:1-99))
???????????????????????????????????±?λ?á?
??????????????????????????
????String.prototype.capitalize = function(){
????return this.replace( /(^|s)([a-z])/g ?? function(m??p1??p2){ return p1+p2.toUpperCase();
????} );
????};
????2??str.match(rgExp)
??????? match ??????????????????? null?? ??????????? match ??????????????飬??????????? RegExp ??????????????????????????????????? (g)????????? 0 ???????????????? 1 ?? n ?????κ????????? ???????δ?????????? exec ???????????????(JavaScript) ??????????????????????????????? 0 ????? n ???????г??????????δ????????????? match ????????????????????????input ?? index?? input ?????????????????????????? index ?????????????????????????????????????????λ?á???????????? i???????????????Сд??
?????塢???????÷???
????1??stringObj.trim() ??????????????????β??????????????
????2??str.toLowerCase() Сд
????3??str.toUpperCase() ??д
??????????????????
?????????????????
????1??string.constructor ??????????????????????
????var x = new String();
????if (x.constructor == String)
????document.write("Object is a String.");
????else
????document.write("Object is not a String.");
????// Output:
????// Object is a String.
????2. string.prototype ???????????????????á?
?????? prototype ????????????????????????? ??????μ????“???”???????????????????
???????磬??????????????????????????????????? String ???????????????????????? String.prototype ?????????
????function string_last( ){
????return this.charAt(this.length - 1);
????}
????String.prototype.last = string_last;
????var myString = new String("every good boy does fine");
????document.write(myString.last());
????// Ou
???????JavaScript ???????????? --???????????????????
?????????????′???
????var a="java"
????a=a+"script"
????console.log(a);//"javascript"
????????a???????????????”java“ ???”javascript“?????????js????????????(?????js????????????)
?????м????????????????????????????????????a??????????????????б???a??????????
???????????????
????var lang = 'Java';
????lang[lang.length-1] = 'S';
????lang[lang.length-1] = 'c';
????console.log(lang);//"java"
????var arr = ['J'?? 'a'?? 'v'?? 'a'];
????arr[arr.length-1] = 'S';
????console.log(arr);// ['J'?? 'a'?? 'v'?? 'S'];
??????????????????js?????Ч???
????var start = new Date();
????var str = "";
????for (var i = 0; i < 1000000; i++) {
????str += "test";
????}
????var end = new Date();
????document.writeln("+?????????????:" + (end.getMilliseconds() - start.getMilliseconds()));
????document.writeln("<br/>");
????var begin = new Date();
????var arry = new Array();
????for (var i = 0; i < 1000000; i++) {
????arry.push("test");
????}
????arry.join("");
????var stop = new Date();
????document.writeln("???鷽??????????????:" + (stop.getMilliseconds() - begin.getMilliseconds()));
???????????????????
??????????′???
????var str="colin";
????var str1=new String("colin");
????str.substring(0??2); //str???????????? ????????????substring??????
????str1.substring(0??2); //str1????
???????????str??????substring???????????????????????????????????“str.substring()"?????????str????????????????????
??????
???·???
??????????????????
2023/3/23 14:23:39???д?ò??????????
2023/3/22 16:17:39????????????????????Щ??
2022/6/14 16:14:27??????????????????????????
2021/10/18 15:37:44???????????????
2021/9/17 15:19:29???·???????·
2021/9/14 15:42:25?????????????
2021/5/28 17:25:47??????APP??????????
2021/5/8 17:01:11