indexOF
indexOf() 方法返回某个指定的字符串值在字符串中首次出现的位置(从左向右)。没有匹配的则返回-1,否则返回首次出现位置的字符串的下标值。

var src="data:images/pic_1.png";
alert(src.indexOf('t'));
alert(src.indexOf('i'));
alert(src.indexOf('g'));

弹出值依次为:-1,0,3

lastIndexOf
lastIndexOf()方法返回从右向左出现某个字符或字符串的首个字符索引值(与indexOf相反)

var src="data:images/pic_1.png";
alert(src.lastIndexOf('/'));
alert(src.lastIndexOf('g'));

弹出值依次为:6,15

js中indexOF和lastIndexOf的更多相关文章

  1. C# 中indexOf、lastIndexOf、subString方法的理解

    一.indexOf() indexOf("\\"):返回"\\"字符在此实例中第一个出现的索引位置,实例的下标是从0开始,如果未找到则返回-1. indexOf ...

  2. javascript中indexOf()和lastIndexOf()详解

    ECMAScript5为数组实例添加两方法:indexOf()和lastIndexOf().这两个方法接受两个参数:要查找的项和(可选的)表示查找起点位置的索引.其中,indexOf()方法从数组的开 ...

  3. JS中indexOf的用法

    String.IndexOf(Char, [startIndex], [count]):返回指定字符在原字符串中的第一个匹配项的索引.可指定字符开始检索位置和指定长度的字符,若没有找到该字符,则返回 ...

  4. java中 IndexOf()、lastIndexOf()、substring()的用法

    public int indexof(String str)返回字符串中出现str的第一个位置 public int indexof(String str,int fromIndex)返回字符串中从f ...

  5. js中indexof()简单使用

    indexOf()方法返回某个指定的字符串值在字符串中首次出现的位置. stringObject.indexOf(searchvalue,fromindex):indexOf()方法对大小写敏感如果要 ...

  6. JS 中的string.lastIndexOf()

    一直转不过来一个弯,就是string.lastIndexOf(searchString,position)  当有position这个参数时,结果是什么 先看代码: var text = 'Missi ...

  7. 转:C#中String类的几个方法(IndexOf、LastIndexOf、Substring)

    String.IndexOf String.IndexOf 方法 (Char, Int32, Int32)报告指定字符在此实例中的第一个匹配项的索引.搜索从指定字符位置开始,并检查指定数量的字符位置. ...

  8. C#中String类的几个方法(IndexOf、LastIndexOf、Substring)

    String.IndexOf String.IndexOf 方法 (Char, Int32, Int32)报告指定字符在此实例中的第一个匹配项的索引.搜索从指定字符位置开始,并检查指定数量的字符位置. ...

  9. java中substring和indexof() 和lastindexof()

    java中substring和indexof() 和lastindexof() str=str.substring(int beginIndex);截取掉str从首字母起长度为beginIndex的字 ...

随机推荐

  1. Codeforces Beta Round #80 (Div. 1 Only) D. Time to Raid Cowavans 离线+分块

    题目链接: http://codeforces.com/contest/103/problem/D D. Time to Raid Cowavans time limit per test:4 sec ...

  2. HDU 5592 ZYB's Premutation

    题目链接: http://acm.hdu.edu.cn/showproblem.php?pid=5592 题意: http://bestcoder.hdu.edu.cn/contests/contes ...

  3. cf 496B Secret Combination

    题目链接:B. Secret Combination You got a box with a combination lock. The lock has a display showing n d ...

  4. Project Facets中Dynamic Web Module无法设置2.5的解决方法

    为什么将jre改到1.6,还是无法改变dynamic web module 到2.5啊 解决方法: 在工程目录下有一个.settings文件夹,打开org.eclipse.wst.common.pro ...

  5. A*(A星)算法python实现

    在春节放假前两天我偶然看到了A\*算法(A\*算法是一个启发式的地图寻路算法),感觉挺有意思.正好放假前也没有什么事情,就花了一个下午写出算法的骨架,节后又花了半天时间完善屏幕输出的细节并且调试完成. ...

  6. php正则过滤html标签、空格、换行符的代码,提取图片

    $descclear = str_replace("r","",$descclear);//过滤换行 $descclear = str_replace(&quo ...

  7. sql server 批量删除数据表

    SET ANSI_NULLS ONGOSET QUOTED_IDENTIFIER ONGO-- =============================================-- Auth ...

  8. App自适应

    http://blog.csdn.net/newjueqi/article/details/42779221

  9. UVA 11181 dfs 概率

    N friends go to the local super market together. The probability of their buying something from them ...

  10. 初学Ajax(三)

    $.ajax() $.ajax()是所有ajax方法中最底层的方法,所有其他方法都是基于$.ajax()方法的封装.这个方法只有一个参数,传递一个各个功能键值对的对象. $.ajax()方法对象参数表 ...