JavaScript检查子字符串是否在字符串中的方法


Posted in Javascript onFebruary 03, 2016

本文实例讲述了JavaScript检查子字符串是否在字符串中的方法。分享给大家供大家参考,具体如下:

var strnew="Hello Raghu How are u"
//Checking existence in entire string
if(strnew.indexOf("Raghu") != -1 )
{
  alert("Exists");
}
/*
Checking existence at the end of string
For example, variable result1 in the following example is assigned 
the value of true because the word "Ishmael" appears at the end of 
the string. Variable result2 is assigned a value of false because 
"Raghu" doesn't appear at the end of the string.
*/
result1 = /Raghu$/.test("Call me Raghu");
result2 = /Raghu$/.test("Call me Raghu. Some years ago");
/*
Checking existence in the begining of string
In the following example, variable result1 is assigned the value 
of true because the word "Birds" appears at the beginning of the 
string. Variable result2 is assigned the value of false because 
"Birds" doesn't appear at the beginning of the string.
*/
result1 = /^Birds/.test("Birds fly");
result2 = /^Birds/.test("Big Birds fly");

希望本文所述对大家JavaScript程序设计有所帮助。

Javascript 相关文章推荐
在textarea中屏蔽js的某个function的javascript代码
Apr 20 Javascript
javascript全局变量封装模块实现代码
Nov 28 Javascript
js中for in的用法示例解析
Dec 25 Javascript
js文件包含的几种方式介绍
Sep 28 Javascript
javascript操作ul中li的方法
May 14 Javascript
jquery实现未经美化的简洁TAB菜单效果
Aug 28 Javascript
原生JS封装ajax 传json,str,excel文件上传提交表单(推荐)
Jun 21 Javascript
全面解析JavaScript中“&&”和“||”操作符(总结篇)
Jul 18 Javascript
Layui数据表格之获取表格中所有的数据方法
Aug 20 Javascript
微信小程序左右滚动公告栏效果代码实例
Sep 16 Javascript
Vue中图片Src使用变量的方法
Oct 30 Javascript
js实现随机点名程序
Sep 17 Javascript
js点击文本框弹出可选择的checkbox复选框
Feb 03 #Javascript
AngularJS实现Model缓存的方式
Feb 03 #Javascript
JS实现CheckBox复选框全选、不选或全不选功能
Jul 28 #Javascript
javascript实现在网页中运行本地程序的方法
Feb 03 #Javascript
简单实现js选项卡切换效果
Feb 03 #Javascript
Eclipse编辑jsp、js文件时卡死现象的解决办法汇总
Feb 02 #Javascript
JavaScript+html5 canvas实现本地截图教程
Apr 16 #Javascript
You might like
php通过array_unshift函数添加多个变量到数组前端的方法
2015/03/18 PHP
老版本PHP转义Json里的特殊字符的函数
2015/06/08 PHP
php实现网站顶踩功能的完整前端代码
2015/07/19 PHP
PHP常用函数总结(180多个)
2016/12/25 PHP
Javascript Global对象
2009/08/13 Javascript
jQuery 表格工具集
2010/04/25 Javascript
jQuery表单获取和失去焦点输入框提示效果的实例代码
2013/08/01 Javascript
Textarea根据内容自适应高度
2013/10/28 Javascript
利用js制作html table分页示例(js实现分页)
2014/04/25 Javascript
一个简单的全屏图片上下打开显示网页效果示例
2014/07/08 Javascript
jQuery中offsetParent()方法用法实例
2015/01/19 Javascript
jQuery的Cookie封装,与PHP交互的简单实现
2016/10/05 Javascript
jQuery模拟完美实现经典FLASH导航动画效果【附demo源码下载】
2016/11/09 Javascript
关于定制FileField中的上传文件名称问题
2017/08/22 Javascript
ES6中Class类的静态方法实例小结
2017/10/28 Javascript
vue cli升级webapck4总结
2018/04/04 Javascript
手动实现vue2.0的双向数据绑定原理详解
2021/02/06 Vue.js
[00:27]DOTA2战队VP、Secret贺新春
2018/02/11 DOTA
Python实现 多进程导入CSV数据到 MySQL
2017/02/26 Python
python编程实现随机生成多个椭圆实例代码
2018/01/03 Python
使用matplotlib画散点图的方法
2018/05/25 Python
Python 中导入csv数据的三种方法
2018/11/01 Python
在Python中将函数作为另一个函数的参数传入并调用的方法
2019/01/22 Python
python使用协程实现并发操作的方法详解
2019/12/27 Python
Python面向对象之多态原理与用法案例分析
2019/12/30 Python
Python编程快速上手——PDF文件操作案例分析
2020/02/28 Python
python3让print输出不换行的方法
2020/08/24 Python
Pytorch 扩展Tensor维度、压缩Tensor维度的方法
2020/09/09 Python
python中子类与父类的关系基础知识点
2021/02/02 Python
档案管理员岗位职责
2013/12/01 职场文书
简历上的自我评价
2014/02/03 职场文书
七年级上册语文教学计划
2015/01/22 职场文书
2015小学语文教师个人工作总结
2015/05/20 职场文书
致毕业季:你如何做好自己的职业生涯规划书?
2019/07/01 职场文书
导游词之丹东鸭绿江
2019/10/24 职场文书
一篇文章带你学习Mybatis-Plus(新手入门)
2021/08/02 Java/Android