易截截图软件、单文件、免安装、纯绿色、仅160KB

javascript 字符串处理全攻略


文章分类:
JavaScript
文章标题:
javascript 字符串处理全攻略
关  键 字:
0
文章作者:
alonglee
文章来源:
http://lmgq.vip.sina.com/tech/jsadvancedlesson/c2p1.htm

发表时间:
2004-9-21 14:43:00


一、声明字符串:
var normal_monkey = "I am a monkey!<br>";
document.writeln("Normal monkey " + normal_monkey);
var bold_monkey = normal_monkey.bold();
document.writeln("Bold monkey " + bold_monkey);
这里的声明: var bold_monkey = normal_monkey.bold();
和下面对声明是等同的: 
var bold_monkey = "<b>" + normal_monkey + "</b>";
第1个版本的声明看起来要简明得多。这里用到了字符串对象中
的bold对象,其他的字符串对象还有indexOf, charAt, 
substring, 以及split, 这些方法可以深入字符串的组成结构。
首先我们研究一下indexOf。
2、indexOf
indexOf用于发现一系列的字符在一个字符串中等位置并告诉你子字符串的起始位置。如
果一个字符串中部包含该子字符串则indexOf返回returns "-1."
例子:
var the_word = "monkey"; 
 //让我们从单词 "monkey"开始。 
var location_of_m = the_word.indexOf("m"); 
 //location_of_m(字母m的位置)将为0,因为字母m位于该字符串的起始位置。
var location_of_o = the_word.indexOf("o"); 
 //location_of_o(字母o的位置)将为1。
var location_of_key = the_word.indexOf("key"); 
 //location_of_key(key的位置)将为3因为子字符串“key”以字母k开始,而k
在单词monkey中的位置是3。
var location_of_y = the_word.indexOf("y"); 
 //location_of_y)字母y的位置)是5。 
var cheeky = the_word.indexOf("q"); 
 //cheeky值是-1,因为在单词“monk


相关文档:

javascript基础学习(五)

利用调用继承的关键只有一步操作:
就是在子类定义时,通过父类的 call 方法,将子类的 this 指针传入。使父类方法在子类上下文中执行。
这样,父类中的所有在父类内部通过 this 方式定义的公有实例成员都会被子类继承。
用 instanceof 运算符判断时,子类的实例化对象只属于子类,不属于父类。
查看子类的实例化对象的 ......

非常全面的实用JavaScript开发工具列表

在今天网络开发方面,JavaScript起了很关键的作用;像jQuery, MooTools, Prototype等等JavaScript框架以及其它JavaScript类库让我们的生活轻松了不少。但是随着Rich Internet Applications(RIA)的面世及迅速应用,书写更强大,更坚实可靠的JavaScript的需要日益迫切。(51CTO编辑:当前Web开发界普遍认为JavaScript将会成为 ......

JavaScript消除字符串空格

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>js除去字符串空格 ......

火星人写的javascript脚本

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html>
<head>
<title>Wanna tell her - interactive DHTML </title>
<meta http-equiv="imagetoolbar" content="no">
<style type="text/css">
html {
overflow: h ......

JavaScript 获取客户端计算机硬件及系统信息


//系统信息获取
function getSysInfo(){
var locator = new ActiveXObject ("WbemScripting.SWbemLocator");
var service = locator.ConnectServer(".");
//CPU信息
var cpu = new Enumerator (service.ExecQuery("SELECT * from Win32_Processor")).item();
var cpuType=cpu.Name,h ......
© 2009 ej38.com All Rights Reserved. 关于E健网联系我们 | 站点地图 | 赣ICP备09004571号