JavaScript檢查子字符串是否在字符串中的方法
本文實(shí)例講述了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");
更多關(guān)于JavaScript相關(guān)內(nèi)容感興趣的讀者可查看本站專題:《JavaScript查找算法技巧總結(jié)》及《JavaScript數(shù)據(jù)結(jié)構(gòu)與算法技巧總結(jié)》
希望本文所述對(duì)大家JavaScript程序設(shè)計(jì)有所幫助。
相關(guān)文章
Javascript在IE和FireFox中的不同表現(xiàn)簡(jiǎn)析
本文將詳細(xì)介紹Javascript在IE和FireFox中的不同表現(xiàn),本人整理了一下,需要的朋友可以參考下2012-12-12
JavaScript使用function定義對(duì)象并調(diào)用的方法
這篇文章主要介紹了JavaScript使用function定義對(duì)象并調(diào)用的方法,實(shí)例分析了javascript中function定義及使用對(duì)象與方法的相關(guān)技巧,需要的朋友可以參考下2015-03-03
JS實(shí)現(xiàn)定時(shí)自動(dòng)消失的彈出窗口
這篇文章介紹了JS實(shí)現(xiàn)定時(shí)自動(dòng)消失的彈出窗口,文中通過示例代碼介紹的非常詳細(xì)。對(duì)大家的學(xué)習(xí)或工作具有一定的參考借鑒價(jià)值,需要的朋友可以參考下2022-04-04
webpack圖片轉(zhuǎn)為base64的實(shí)現(xiàn)示例
在開發(fā)過程中,圖片轉(zhuǎn)成base64是常有的事,本文主要介紹了webpack圖片轉(zhuǎn)為base64的實(shí)現(xiàn)示例,具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下2021-12-12
javascript 文本框水印/占位符(watermark/placeholder)實(shí)現(xiàn)方法
html5為表單元素(type為text/password/search/url/telephone/email)新增了一個(gè)placeholder屬性,為輸入框提供一種提示2012-01-01
純javascript實(shí)現(xiàn)選擇框的全選與反選功能
這篇文章主要介紹了純javascript實(shí)現(xiàn)選擇框的全選與反選 ,需要的朋友可以參考下2019-04-04

