1) Return the length of a string
var txt = "Hello World!";
document.write(txt.length);
2) Style strings
var txt = "Hello World!";
document.write("<p>Big: " + txt.big() + "</p>");
document.write("<p>Small: " + txt.small() + "</p>");
document.write("<p>Bold: " + txt.bold() + "</p>");
document.write("<p>Italic: " + txt.italics() + "</p>");
document.write("<p>Fixed: " + txt.fixed() + "</p>");
document.write("<p>Strike: " + txt.strike() + "</p>");
document.write("<p>Fontcolor: " + txt.fontcolor("green") + "</p>");
document.write("<p>Fontsize: " + txt.fontsize(6) + "</p>");
document.write("<p>Subscript: " + txt.sub() + "</p>");
document.write("<p>Superscript: " + txt.sup() + "</p>");
document.write("<p>Link: " + txt.link("http://www.w3schools.com") + "</p>");
document.write("<p>Blink: " + txt.blink() + " (does not work in IE, Chrome, or Safari)</p>");
3) Convert a string to lower case or upper case letters.
var txt="Hello World!";
document.write(txt.toLowerCase() + "<br />");
document.write(txt.toUpperCase() + "<br />");
4) search for a specified value within a string.
var str="Hello world!";
document.write(str.match("world") + "<br />");
document.write(str.match("World") + "<br />");
document.write(str.match("worlld") + "<br />");
document.write(str.match("world!"));
5) replace a specified value with another value in a string.
var str="Visit Microsoft!";
document.write(str.replace("Microsoft","W3Schools"));
6) return the position
var str="Hello world!";
document.write(str.indexOf("d") + "<br />");
document.write(str.indexOf("WORLD") + "<br />");
document.write(str.indexOf("world"));
7) Regular Expression
// perform case-insensitive matching (ignore case)
var str = "Visit W3Schools";
var patt = /w3schools/i;
document.write(str.match(patt));
document.write("<br/>");
// perform a (global) match
// find all matches rather than stopping after the first match
var str="Is this all there is?";
var patt=/is/g;
document.write(str.match(patt));
document.write("<br/>");
var str="Is this all there is?";
var patt=/is/gi;
document.write(str.match(patt));
// test
var patt=new RegExp("e");
document.write(patt.test("The best things in life are free"));
document.write("<br/>");
// execute
var patt=new RegExp("e");
document.write(patt.exec("The best things in life are free"));
// replace
var str="Every man in the world! Every woman on earth!";
var patt=/man/g;
var str=str.replace(patt,"person");
document.write(str+"<br />");
patt=/(wo)?man/g;
patt.compile(patt);
str=str.replace(patt,"person");
document.write(str);
分享到:
相关推荐
javascript string和array常用扩展方法
Javascript之String对象详解_.docx
JavaScript String 对象参考手册
javascript笔记 String类replace函数的一些事.docx
JavaScript Math、String函数
主要介绍了JavaScript中string转换成number介绍,本文讲解了3种将string值转换成number的方法,需要的朋友可以参考下
主要介绍了Javascript实现Array和String互转换的方法,涉及JavaScript中toString方法与split方法的使用技巧,需要的朋友可以参考下
BitVector CookieUtil DES FileUtil HttpUtil ImageFile JavaScriptString JsonHelper StringUtil Thumbnail Utils WebFileInfo
JavaScript String 对象参考手册 字符串是 JavaScript 的一种基本的数据类型。 String 对象的 length 属性声明了该字符串中的字符数。String 类定义了大量操作字符串的方法。 需要注意的是,JavaScript 的字符串是不...
NULL 博文链接:https://shuaigg-babysky.iteye.com/blog/458603
日期转换,long类型时间转换成string类型
matlab开发-未经许可的Javascriptstring。手动解释可能包含转义字符的javascript字符串。
javascript常常会出现"缺少对象
通过Javascript实现唐诗三百首在网页中的三种展示方式,使初学者可以详细了解String对象的多个方法的应用。
2、String对象常用属性及方法 成员 类型 作用 length 属性 获取字符串的长度 charAt(index) 方法 获取index位置的字符,位置从0开始计算 indexOf(searchValue) 方法 获取searchValue在字符串中首次出现的位置 ...
JavaScript中的String对象.pdf 学习资料 复习资料 教学资源
String 的扩展方法集合,可以是javascript对string的功能更多
input id=”txtNum” type=”text” value=”1″ runat=”server” onchange=”[removed]checkNum();” /> 件(库存”getGoodsNum”> <%=GOODSNUM%>)件 用JS取值,注意看JS代码: 代码如下: var num = ...
15、分析javascript代码段,输出结果是: B var a="125.8765"; c=parseInt(a); d=parseFloat(a); document.write(c+" "+d) A) 125.8765 126 B) 125 125.8765 C) 125.8765 125 D) 126 125.8765