JSFiddle - React, Tailwind, and code Playground

by bobbyfrancisjoseph

HTML

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Text Search</title>
<script type="text/javascript" src="js/jquery-1.7.1.min.js"></script>
<script type="text/javascript" src="js/flipbook.js"></script>
 
</head>

<body>

<textarea id="txtSearch" rows="300" cols="200">
Preface No matter what kind of ninja you are a cooking ninja, a corporate lawyer ninja, or  an actual ninja ninja—virtuosity lies in first mastering the basic tools of the trade. Once conquered, it’s then up to the full fledged ninja to apply that knowledge in  creative and inventive ways.  In recent times, jQuery has proven itself to be a simple but powerful tool for taming  and transforming web pages, bending even the most stubborn and aging browsers  to our will. jQuery is a library with two principal purposes: manipulating elements  on a web page, and helping out with Ajax requests. Sure,  there are quite a few  commands available to do this—but they’re all consistent and easy to learn. Once  you’ve chained together your first few actions, you’ll be addicted to the jQuery  building blocks, and your friends and family will wish you’d never discovered it!  On top of the core jQuery library is jQuery UI: a set of finelooking controls and  widgets (such as accordions, tabs, and dialogs), combined with a collection of fullfeatured  behaviors for implementing controls of your own. jQuery UI lets you quickly  throw together awesome interfaces with little effort, and serves as a great example  of what  you can achieve with a little jQuery know‐how.  At its core, jQuery is a tool to help us improve the usability of our sites and create  a better user experience. Usability refers to the study of the principles behind an  object’s perceived efficiency or elegance. Far from being merely flashy, trendy design, ...

JavaScript

// JavaScript Document
 
 var searchString;
 
 var pagesArray = [];

 $(document).ready(function() {
    searchString = $('#txtSearch').text();
    
    pagesArray = searchString.split(unescape('%0C'));
    
    var noOfPages  = pagesArray.length - 1;
    
    var arrayLength = pagesArray.length

    var searchString = 'Preface No matter what';
    
    var resultArray = create2DArray(arrayLength);
    
    
    for (var i=0;i<arrayLength;i++)
    {
      resultArray[i] = occurrences(pagesArray[i],searchString)
    }
    
    //console.log(pagesArray[0]);
    
    for (var j=0;j<resultArray.length;j++)
    {    
         if(resultArray[j].length != 0)
         {
            console.log("The given data is found on page: "+ (j+1))
         }    
     
    }  
    
    
 })
 
 function occurrences(string, substring){
      
            
    var n=0;
    var pos=0;
    
    var tempArray = [];
    
   
    while(true){
        
        /*console.log(string,substring)*/
       
        pos=string.indexOf(substring,pos);
        
        //console.log(pos);
        
        
        if(pos!=-1){
            
            tempArray.push(pos);
            n++;
            pos+=substring.length;
       
       }
        else
        {
            break;
        }
    }

    return(tempArray);
    
}
    


function create2DArray(rows) {
    
  var arr = [];

  for (var i=0;i<rows;i++) {
     arr[i] = [];
  }

  return arr;
}