1.串的切割

var a="hello world";//a.length=11
alert(a.slice(3));
alert(a.substring(3));
alert(a.substr(3));//三个都lo world

alert(a.slice(3,7));//3到7
alert(a.substring(3,7));//3~7
alert(a.substr(3,7))//3后面7个字符

alert(a.slice(-3));//a.length-3开始,11-3=8="rld";
alert(a.substring(-3));//substr会当作是0,hello world;
alert(a.substr(-3));//和slice模式一样

alert(a.slice(3,-4));//(3,a.length(11-4=7))lo w
alert(a.substring(3,-4));//当作(3,0),又有自己调整为(0,3)的特性,hel
alert(a.substr(+3,-4));//也会当作(3,0),后面参数为0 自然就是“”(空串)

2 string indexOf

var a="hello world);

a.indexOf("o");//4

a.lastIndexOf("0");//7

a.indexOf("o",6)//在第6个开始

a.lastIndexOf("o",6)

3.trim()删除空格

4.toLowerCase()大小写

 toUpperCase()

5.串里面查找

1)match()和RegExp一样

var a="hello world";
var b=/lo/;
var c=a.match(b);
console.log(c[0],c.index,c.lastIndex);

2)search()只返回第一的位置,像c.index

var a="hello world";
var b=/lo/;
var c=a.search(b);
console.log(c[0],c.index,c.lastIndex);//三个都是undefined
console.log(c);

6 串的方便替换

var a="cat,bat,fat,dat";
var b=a.replace(/at/g,"fuck");
console.log(b);

第二个参数还可以加段编码,更新匹配结果

var a="cat,bat,fat,dat";
var b=a.replace(/(.at)/g,"fuck($2)");

还可以是个函数function(match,pos,originalText)分别是模式的匹配项,匹配项在字符串的位置,原始字符(前面的match)

var a="<000<0.00<>0<.0";
var b=a.replace(/[<>.]/g,function (match,pos,originalText) {
switch(match){
case "<":
case ">":
return "1";
case ".":
return originalText;//<>.这些
}
});
console.log(b);

7串化为数组

var a="sdds,sf,we,zc";
var b=a.split(",");
var c=a.split(/[/,]/);
console.log(b,c);

8串的比较

var a="fuck";
var b="e";
console.log(a.localeCompare(b));//不能直接减

9 fromCharCode()方法

String.fromCharCode(104,101,108,108,111));编码转换为字符hello

string的一些操作,类似数组的更多相关文章

  1. JQuery操作类数组的工具方法

    JQuery学习之操作类数组的工具方法 在很多时候,JQuery的$()函数都返回一个类似数据的JQuery对象,例如$('div')将返回div里面的所有div元素包装的JQuery对象.在这中情况 ...

  2. C#中对string与string[]的初步操作

    开篇之作,简单的对string与string[]进行初步操作,入门篇也,不多说,直接上代码. using System; using System.Collections.Generic; using ...

  3. C# 对包含文件或目录路径信息的 System.String 实例执行操作

    在字符串操作中有一类比较特殊的操作,就是对包含文件或目录路径信息的 System.String 实例执行操作.比如根据一个表示路径的字符串获取其代表的文件名称.文件夹路径.文件扩展名等.在很多时候,我 ...

  4. C++ Primer : 第九章 : vector变长、string的其他操作以及容器适配器

    vector变长机制.string的其他构造方法,添加.替换和搜索操作,string比较和数值转换,最后是容器适配器. vector对象是如何增长的 vector和string类型提供了一些成员函数, ...

  5. 将String类型的二维数组中的元素用FileOutputStream的write方法生成一个文件

      将String类型的二维数组中的元素用FileOutputStream的write方法生成一个文件import java.io.File;import java.io.FileOutputStre ...

  6. Python学习笔记5-字符串、bool、数值操作和数组字典排序

    1.字符串 # 字符串数字之间转换 # x = int("6") # print type(x) #<type 'str'> # y = str(6) # print ...

  7. Java的string学习笔记 与char数组和bufferstring的比较

    ---恢复内容开始--- 一直用的C 导致这种类望而生畏 现在终于鼓起勇气学习一下 首先学习string类型 String s1 = "AbCdEf"; String s2 = & ...

  8. C# 类如何声明索引器以提供对类的类似数组的访问的代码

    研发期间,将内容过程中比较常用的内容段做个收藏,如下内容内容是关于 C# 类如何声明索引器以提供对类的类似数组的访问.的内容,希望能对各位有用处. using System;using System. ...

  9. C风格字符串和C++ string 对象赋值操作的性能比较

    <<C++ Primer>> 第四版 Exercise Section 4.3.1 部分Exercise 4.2.9 习题如下: 在自己本机执行如下程序,记录程序执行时间: # ...

  10. 操作 numpy 数组的常用函数

    操作 numpy 数组的常用函数 where 使用 where 函数能将索引掩码转换成索引位置: indices = where(mask) indices => (array([11, 12, ...

随机推荐

  1. 前台任意页面调用自定义字段选项 box 单选 多选方法及查询

    在模板页增加函数,函数写法比较特殊,但是v9模板引擎nb,能够识别   <?              function xbox($field,$na){               $a=p ...

  2. C++快速排序实现(quicksort)

    quicksort:分治思想. 分解:数组A[p, r)被划分成两个子数组A[pq) 和 A[q+1, r),使得A[pq)中的每个元素小于等于A[q], A[q]也小于A[q+1r)中的每个元素.q ...

  3. JDK TOMCAT MAVEN在myeclipse如何配置

    对于没有基础的人来说,本工具务必放在D盘根目录下. 1配置环境变量, "我的电脑-->右键-->属性" 貌似是这样吧,我电脑桌面没"我的电脑"或&q ...

  4. CentOS安装MySQL问题汇总

    遇到的错误 ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using password: NO) denied for ...

  5. ossim

    http://edu.51cto.com/index.php?do=lession&id=23039 http://www.tudou.com/home/ossim/item

  6. 颠覆你的时空观-----理解傅立叶transform

    在知乎上看到的,非常不错,最起码知道为什么了: 傅立叶变换,拉普拉斯变换,z变换这三种方法的本质主要就是将信号从时域转换成频域,因为频域更好展开分析 = =. 频域只是另一种看到信号的角度(世界观). ...

  7. YII 事件event和行为Behavior

    To declare an event in your CComponent child class, you should add a method with aname starting with ...

  8. 设计模式(十二): Flyweight享元模式 -- 结构型模式

    说明: 相对于其它模式,Flyweight模式在PHP实现似乎没有太大的意义,因为PHP的生命周期就在一个请求,请求执行完了,php占用的资源都被释放.我们只是为了学习而简单做了介绍. 1. 概述 面 ...

  9. HDOJ(HDU) 1407 测试你是否和LTC水平一样高(暴力)

    Problem Description 大家提到LTC都佩服的不行,不过,如果竞赛只有这一个题目,我敢保证你和他绝对在一个水平线上! 你的任务是: 计算方程x^2+y^2+z^2= num的一个正整数 ...

  10. VS013的单元测试去哪里了

    需要安装这个插件 http://visualstudiogallery.msdn.microsoft.com/45208924-e7b0-45df-8cff-165b505a38d7