js中String对象
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>New Web Project</title>
<script type="text/javascript">
function fun()
{
var str=new String("Test");
console.log("");
console.log("1)属性length");
console.log(str.length);//输出字符串的长度
console.log("2)方法charAt(n)");
console.log(str.charAt(0));//返回字符串中第n个字符
console.log(str.charAt(1));//返回字符串中第n个字符
console.log(str.charAt(2));//返回字符串中第n个字符
console.log("3)方法concat(value,...)");
var str1=" js";
var str2=" html";
console.log(str.concat(str1,str2));//将一个或多个值连接到字符串上
//concat函数并不改变原有字符串
console.log("4)输出String对象比较");
console.log(str.toString());//返回String对象的值
console.log(str);//直接将str以对象的形式输出
console.log(str.valueOf());//返回String对象的值
console.log("5)输出大小写的形式");
console.log("大写形式:"+str.toUpperCase());
console.log("原来的字符串内容并不发生改变:str="+str.toString());//返回String对象的值
console.log("小写形式:"+str.toLowerCase());
console.log("6)substring()返回字符串的一部分");
console.log(str.substring(1,3));
console.log("7)slice()返回字符串的一部分");
console.log(str.slice(1,3));
console.log("8)在字符串中查找子字符串第一次和最后一次出现的位置");
str =new String("Test233Test233Test");
str3="233";
console.log("str="+str.toString());
console.log(str.indexOf(str3));
console.log(str.lastIndexOf(str3));
console.log("9)将字符串分隔为字符串数组split()");
str =new String("wo shi hao ren");
console.log("str="+str.toString());
console.log(str.split(" "));
ary=str.split(" ");
for(var i=0;i<ary.length;i++)
{
console.log(ary[i]);
}
}
fun();
</script>
</head>
<body>
<h1>New Web Project Page</h1>
</body>
</html>

待续。。。
js中String对象的更多相关文章
- JS中string对象的一些方法
原文地址(包含所有的string对象的方法): http://www.dreamdu.com/javascript/object_string/ string.slice(startPos,endP ...
- JS中String对象常用的方法
1. stringObject.charAt(index) 参数:index 必需,即字符在字符串中的下标. 返回值: 返回在指定位置的字符.返回的字符是长度为 1的字符串.(length属性 ...
- js中判断对象具体类型
大家可能知道js中判断对象类型可以用typeof来判断.看下面的情况 <script> alert(typeof 1);//number alert(typeof "2" ...
- 浅解析js中的对象
浅解析js中的对象 原文网址:http://www.cnblogs.com/foodoir/p/5971686.html,转载请注明出处. 前面的话: 说到对象,我首先想到的是每到过年过节见长辈的时候 ...
- js中XMLHttpRequest对象实现GET、POST异步传输
js中XMLHttpRequest对象实现GET.POST异步传输 /* * 统一XHR接口 */ function createXHR() { // IE7+,Firefox, Opera, Chr ...
- JavaScript基础13——js的string对象
<!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <title> ...
- JS中String类型转换Date类型 并 计算时间差
JS中String类型转换Date类型 1.比较常用的方法,但繁琐,参考如下:主要使用Date的构造方法:Date(int year , int month , int day)<script& ...
- js中推断对象详细类型
大家可能知道js中推断对象类型能够用typeof来推断. 看以下的情况 <script> alert(typeof 1);//number alert(typeof "2&quo ...
- Js的String对象
Js的String对象常用方法: 方法一.得到某字符在字符串中的索引位置. str.indexOf(findStr,[index])--返回的是要查找字符在字符串中的位置索引 ,index开始查找 ...
随机推荐
- java记事本
新知识点 1.撤销 textArea添加一个实现监听接口的类(添加了之后可以一直监视着添加的删除的情况,以便来撤销 textArea.getDocument().addUndoableEditList ...
- ajax+XMLHttpRequest里的FormData实现图片异步上传
发这篇博客的时候我是自己在研究这个XMLHttpRequest请求,在别人的博客上面知道XMLHttpRequest新加了一个FormData的东西,好像现在APP请求后台也有用这种方式的吧. 别的不 ...
- mysql hash索引优化
创建表 CREATE TABLE `t1` ( `id` int(11) NOT NULL AUTO_INCREMENT, `msg` varchar(20) NOT NULL DEFAULT ' ...
- python学习第十六天 --继承进阶篇
这一章节主要讲解面向对象高级编程->继承进阶篇,包括类多继承介绍和继承经典类和新式类属性的查找顺序不同之处. 多继承 上一章节我们讲到继承,子类继承父类,可以拥有父类的属性和方法,也可以进行扩展 ...
- python文件处理
python中对文件处理需要涉及到os模块和shutil模块得到当前工作目录路径:os.getcwd()获取指定目录下的所有文件和目录名:os.listdir(dir)删除文件:os.remove(f ...
- 堆排序(Heap Sort)的C语言实现
堆排序(Heap Sort)具体步骤为 将无序序列建成大顶堆(小顶堆):从最后一个非叶子节点开始通过堆调整HeapAdjust()变成小顶堆或大顶堆 将顶部元素与堆尾数组交换,此是末尾元素就是最大值, ...
- HDU1276(士兵队列训练模拟与链表)
HDU1276 Time Limit:1000MS Memory Limit:32768KB 64bit IO Format:%I64d & %I64u Descripti ...
- cms中if标签的使用
<#if order.EnFriendly ?? && order.EnFriendly==1> <td class="text-center"& ...
- hdu 3400 Line belt
题意:给你两条线段AB,CD:然后给你在AB,CD上的速度P,Q,在其它部分的速度是R,然后求A到D的最短时间. 思路:用三分枚举从AB线段上离开的点,然后再用三分枚举在CD的上的点找到最优点,求距离 ...
- 转一篇:Hyper-V和VMware的高可用实时迁移技术详解
ESX里以集群的ha.drs.dpm功能实现 HYPER-V里以集群+共享存储实现. ~~~~~~~~~~ 微软公司的Hyper-V虚拟化管理程序一经面世就引发了业界的普遍关注.本文意在对Hyper- ...