zoukankan      html  css  js  c++  java
  • JavaScript lastIndexOf() 方法

    定义和用法

    lastIndexOf() 方法可返回一个指定的字符串值最后出现的位置,在一个字符串中的指定位置从后向前搜索。

    语法

    stringObject.lastIndexOf(searchvalue,fromindex)

    返回值

    如果在 stringObject 中的 fromindex 位置之前存在 searchvalue,则返回的是出现的最后一个 searchvalue 的位置。

    说明

    该方法将从尾到头地检索字符串 stringObject,看它是否含有子串 searchvalue。开始检索的位置在字符串的 fromindex 处或字符串的结尾(没有指定 fromindex 时)。如果找到一个 searchvalue,则返回 searchvalue 的第一个字符在 stringObject 中的位置。stringObject 中的字符位置是从 0 开始的。

    提示和注释

    注释:lastIndexOf() 方法对大小写敏感!

    注释:如果要检索的字符串值没有出现,则该方法返回 -1。

    实例

    在本例中,我们将在 "Hello world!" 字符串内进行不同的检索:

    <script type="text/javascript">
    
    var str="Hello world!"
    document.write(str.lastIndexOf("Hello") + "<br />")
    document.write(str.lastIndexOf("World") + "<br />")
    document.write(str.lastIndexOf("world"))
    
    </script>

    以上代码的输出:

    0
    -1
    6

    OCX:自定义一个多个相机类型并转换字符串的数组

       static const StCamStyle stCamStyle[] =
       {

          ......

           {{SONY_IMX185_MIPI_1080P_30FPS}, _T("SONY_IMX185_MIPI_1080P_30FPS")},
           {{ELE_TW9960_CAM_960_25}, _T("ELE_TW9960_CAM_960_25")} 
        };

    JS:解析相机类型

       /*******************************通过相机类型在加载窗体时显示加载分辨率**************************************/
       function showVideoResolution() {
       strGetCam = parent.parent.Cmr.JSGetUnModAttr(); //得到相机类型
       var i = 0;
       while (i < strGetCam.length) { //循88环查找相机特殊字段
       var index = strGetCam.lastIndexOf('_');
       if (index != -1) { //存在分隔字符‘_’
       strs = strGetCam.substr(index + 1, strGetCam.length); //查询相机特殊字段(分辨率)
       strGetCam = strGetCam.substring(0, index); //攫取最后一位后的剩余字段
       //如遇特殊字符(分辨率),停止循环
          if (strs == "1080" || strs == "1080P" || strs == "720P" || strs == "960" || strs == "960P" || strs == "800P" || strs == "1536" || strs == "1920" || strs == "D1P" || strs == "1024P")       {
               break;
          }
          else

          { //没有遇见继续
              continue;
           }
      }
      else

      { //不存在分隔字符‘_’跳出循环
           break;
      }
      }

    
    
  • 相关阅读:
    带横线圆圈标题
    锚点点击导航 跳转到相应位置,样式随之变化
    导航随滚动改变样式
    for循环中嵌套函数,执行顺序和结果该如何理解?
    mui 记录
    获取页面所有a标签href
    cookie记录横向滚动条位置
    Istio全景监控与拓扑
    Istio 流量治理功能原理与实战
    Cloud Native Weekly | KubeCon首登中国,华为云亮相KubeCon 2018,微软云服务又罢工
  • 原文地址:https://www.cnblogs.com/OnlyLV520/p/8318029.html
Copyright © 2011-2022 走看看