*字符串截取方法*/

var s="abc_def[ghi]jk[i]";

var temp;
function CopyFromStr(str_source,str_key, bl_containKey)
{
  if(str_source.indexOf(str_key)==-1)
 { return "";}
  else
 {
    if(bl_containKey)
     { return str_source.substr(str_source.indexOf(str_key), str_source.length - str_source.indexOf(str_key) + 1);}
    else 
     { return str_source.substr(str_source.indexOf(str_key)+str_key.length, str_source.length - str_source.indexOf(str_key)+str_key.length + 1);}
  }
}

function CopyToStr(str_source,str_key,bl_containKey)
{
  if(str_source.indexOf(str_key)==-1)
 { return "";}
  else
 {
    if(bl_containKey)
     { return str_source.substr(0, str_source.indexOf(str_key) + str_key.length);}
    else 
     { return str_source.substr(0, str_source.indexOf(str_key) );}
  }
}

function CopyStr(str_source,str_start,str_end,bl_containStartEnd)
{
  var i,j;
  var tmp;
  tmp = str_source;
  i = tmp.indexOf(str_start);
  if(i==-1) {return "";}
  tmp = CopyFromStr(tmp,str_start,false);
  j = tmp.indexOf(str_end);
  if(j==-1) {return "";}

if(bl_containStartEnd)
   {return str_start + tmp.substr(0, j) + str_end;}
  else
   {return tmp.substr(0,j);}
}
    
    
function CopyStrEx(str_source, str_key, str_start,str_end,bl_containStartEnd)
{
  var tmp = str_source;
  if((tmp.indexOf(str_key)==-1)  ||
     (tmp.indexOf(str_start)==-1) ||
     (tmp.indexOf(str_end)==-1) )
 {return "aaa";}
 else
 {
  tmp = CopyFromStr(tmp,str_key,false); 
  if(bl_containStartEnd)
   {return CopyStr(tmp,str_start,str_end,true);}
  else
   {return CopyStr(tmp,str_start,str_end,false);}
  } 
}

function RightFromStr(str_source,str_key,bl_containStartEnd)
{
  if(str_source.indexOf(str_key)==-1)
 { return "";}
  else
 {

while(str_source.indexOf(str_key)>-1)
  {str_source = CopyFromStr(str_source,str_key,false);}

if(bl_containKey)
     { return str_key+str_source;}
    else 
     { return str_source;}
  }
}

function RightFromStr(str_source,str_key,bl_containStartEnd)
{
  if(str_source.indexOf(str_key)==-1)
 { return "";}
  else
 {
   while(str_source.indexOf(str_key)>-1)
   {str_source = CopyFromStr(str_source,str_key,false);}
    if(bl_containStartEnd)
     { return str_key+str_source;}
    else 
     { return str_source;}
  }
}

/*调用方法:*/
temp=CopyFromStr(s, '[gh', false);alert(temp);
temp=CopyToStr(s,   '[gh', false);alert(temp);
temp=CopyStr(s,      '_',  '[gh',  false);alert(temp);
temp=CopyStrEx(s,    '_',  '[',    ']',  false);alert(temp);

temp=RightFromStr(s, '[',  false);alert(temp);

谷歌浏览器内核Cef js代码整理(三) 字符串处理的更多相关文章

  1. 谷歌浏览器内核Cef js代码整理(一)

    尊重作者原创,未经作者允许不得转载!作者:xtfnpgy,原文地址: https://www.cnblogs.com/xtfnpgy/p/9285359.html 一.js基础知识 <!--   ...

  2. 谷歌浏览器内核Cef js代码整理(二) 滚动条

    1.隐藏滚动条 document.documentElement.style.overflow = 'hidden';隐藏竖向滚动条:document.documentElement.style.ov ...

  3. webpages框架使用@razor语法向js代码传递Json字符串

    进入web开发时间太短,一个人尝试着做了几个初级项目,遇到了太多的困难.尽管不是学开发专业的,仅为爱好所以硬着头皮坚持了下来. 将遇到的问题记录下来,备查. 使用vs2015中asp.net razo ...

  4. 常用js代码整理、收集

    个人整理了一下个人常用到的一些js代码,以方便学习以及日后使用,或许有一些是个人之前从网上摘下来的,但是不记得是具体从哪里来的了,如果你看到有一段代码跟你的文章很相似甚至一样,请不要气愤,请告诉我,我 ...

  5. c#: WebBrowser控件注入js代码的三种方案

    聊做备忘. 假设js代码为: string jsCode = @"function showAlert(s) {{ alert('hello, world! ' + s);}}; showA ...

  6. 常用JS代码整理

    1: function request(paras) { 2: var url = location.href; 3: var paraString = url.substring(url.index ...

  7. 判断点击第几个按钮JS代码的三种方法

    方法一:使用下标实现<!DOCTYPE html> <html> <head> <meta charset="UTF-8"> < ...

  8. JS代码把JSON字符串转换为对象,计算对象的长度并把它转换为数字类型,把转换的值相加减

    Number(JSON.parse(rowObject.RenewalProperty).length)-1

  9. 【JS学习】-利用谷歌浏览器调试JS代码(转)

    谷歌浏览器是常用来调试JS代码的工具,本文主要介绍如何利用谷歌浏览器来调试JS代码,协助我们进行开发工作. 首先,打开谷歌浏览器,按快捷键F12或者ctrl+shift+j,就可以打开谷歌浏览器的开发 ...

随机推荐

  1. 蒙特·卡罗方法(Monte Carlo method)

    蒙特·卡罗方法(Monte Carlo method),也称统计模拟方法,是二十世纪四十年代中期由于科学技术的发展和电子计算机的发明,而被提出的一种以概率统计理论为指导的一类非常重要的数值计算方法.是 ...

  2. kaptcha验证码插件使用与参数

    kaptcha使用1 kaptcha使用2 kaptcha使用3 kaptcha参数说明

  3. <文档学习>AirSim/using_car.md Choosing Your Vehicle: Car or Multirotor

    如何在AirSim中使用汽车 默认情况下,AirSim中使用的车型为多转子multirotor. 如果你想使用汽车,那么只需在你的settings.json(https://github.com/Mi ...

  4. apache 与 php-fpm 几种处理方式

    目录 1.SetHandler 2.ProxyPassMatch 3.ProxyPass 1.SetHandler 在apache配置文件只部署一次 需要Apache 2.4.9以上才行 ip:por ...

  5. python3+requests+unittest:接口自动化测试(一)

    转载请表明出处:https://www.cnblogs.com/shapeL/p/9179484.html 简单介绍框架的实现逻辑,参考代码的git地址: https://github.com/zha ...

  6. single-cell RNA-seq 工具大全

    [怪毛匠子-整理] awesome-single-cell List of software packages (and the people developing these methods) fo ...

  7. 通用base.css —— 《编写高质量代码 web前端开发修炼之道》

    @charset "utf-8"; /*CSS reset*/ html{color:#000;background:#FFF;} body,div,dl,dt,dd,ul,ol, ...

  8. 利用maven的profiles灵活的配置多环境

    <!--多环境配置--> <profiles> <profile> <id>dev</id> <activation> < ...

  9. 创建ApplicationContext与BeanFactory时的区别-Spring源码学习之容器的基本实现

    传送门 可以加载XML两种方法 使用 BeanFactory 加载 XML BeanFactory bf = new XmlBeanFactory(new ClassPathResource(&quo ...

  10. Parsing Natural Scenes and Natural Language with Recursive Neural Networks-paper

    Parsing Natural Scenes and Natural Language with Recursive Neural Networks作者信息: Richard Socher richa ...