Want to become a Vibe Coder? Join Vibe Coding Training here
x
C# Corner
Tech
News
Videos
Forums
Jobs
Books
Events
More
Interviews
Live
Learn
Training
Career
Members
Blogs
Challenges
Certification
Contribute
Article
Blog
Video
Ebook
Interview Question
Collapse
Feed
Dashboard
Wallet
Learn
Achievements
Network
Refer
Rewards
SharpGPT
Premium
Contribute
Article
Blog
Video
Ebook
Interview Question
Register
Login
Serach String from Pagragraph using JavaScript?
WhatsApp
Sagar Pardeshi
Oct 02
2014
2
k
0
0
<script type=
"text/javascript"
language=
"JavaScript1.1"
>
<!--
// Declare variables
var
pos = 0;
var
num = -1;
var
i = -1;
var
graf =
"This is a test This is a test This is a test dsadasad This is a test adadasdsa This is a test fdsfdsfdsf This is a test "
;
// Search the string and counts the number of e's
while
(pos != -1)
{
pos = graf.indexOf(
"This is a test"
, i + 1);
num += 1;
i = pos;
}
// Write the response to the page
document.write(graf+
"<br>"
)
document.write(
"There were "
+ num +
" e's in that paragraph."
); document.close();
//-->
</script>This is a test This is a test This is a test dsadasad This is a test adadasdsa This is a test fdsfdsfdsf This is a test <br>There were 6 e's
in
that paragraph.
serach string using Javascript
Up Next
Serach String from Pagragraph using JavaScript?