Searching For Multiple Words Within A String Or Array?
Nov 6, 2010
How would one search for more than one one simultaneously? I have this function:
var flix = ["Any items left unattended on this table" , "Hello, World"];
var a = flix.toLowerCase();
var b = s.toLowerCase();
var result = a.indexOf(b)
if (result >= 0)
It's pretty basic, it just searches through the first index of var flix and tells me if the parameter (s) is 'found' or 'not found'. I made it not to be case sensitive. However, how would I search for multiple words for example:
Multiwords("ANY items This") and if any combination of 'ANY' or 'items' or 'This' is found, i still get my alert message of 'Found'?
I am working on a little project where I have a form that allows a user to input a sentence that will be sorted alphabetically when they click sort. The result should be displayed in the Output box at the bottom. Then They should be able to enter a string that will be search from the previous sentence entered and that search will display in the output as well. Then last they should be able to enter in a replacement string; however, I have not done much reading on that so I am completely clueless there.
I thought I would start with the small stuff and last I would work on the replacement string. So I have the form done, but I seem to be struggling with the functions. I think I should use aname.sort to sort the words in ABC order. I am wondering if I am just completely off on how I am trying to do all of this. Any tips would be great, just to maybe point me in the right direction. Code:
I am trying to search an array for a string and then if it is found alert it. I have found examples of how to iterate the array and how to use .IndexOf to return a true false statement as to whether the array includes the string, but i don't know what to do after that and how to display the string if its found.
- Asks the User to select a date (year, month, day) via drop-down boxes- Converts whatever the user inputs to a formal that will match a string value found in an imported array in a .js file... And what I'm having trouble with:- Searching through the imported array for a matching value- Printing whatever block of the array matches the value, as well as any others that also match the value.
For starters, because the array I'm working with is enormous, I'll just make one up here that is still in the same format. In working with the main code, assume that this is the cdr.js file:
I feel stupid for asking a question about searching arrays, when there's a very similar thread that has been answered just recently on the first page; however, I'm still having trouble contemplating my own scenario.Basically, my program prompts the user for the length of the array and then asks the user to fill the array with words.I want to confirm if the user wants to search the array for those words. If so, the user will then be prompted to enter the word he wishes to search for; if found, the location of that word will be reported and the number of times the word has been searched for will be kept track of in a separate array.Here is what I have so far:
/* -- phase 3 ------------------------------------------------------ search for words the user asks for */
I want to make a search field for my site where the user can enter his query then select which site he would like to search the query on. Like www.torrents.to has, basically just like that. I know nothing about coding, could somebody write the code for me and tell me where to put my links, directory stuff etc...?
I've new to the dream.in.code community and I've heard you guys are the best to offer advice, so here we go. Right now, I'm working on a assignment where I'm trying to randomly distribute a word string into a 16/16 table. The idea is that it would display the words from the string in reversed order(i.e. the words can only be displayed in four directions in reverse: diagonally up, diagonally down, down-to-up and right-to-left, so something is "FOUR" becoming "ROUF" is allowed). So far, I've created the table and have used the string.split method to make my string to an array, but I'm difficulty figuring out how to get the reversed order and random distribution part down. I've also attached the instructions sheet for further clarification of my task.
I was wondering how to have the names listed line-by-line in two text files (first name, surname) and to call the files when the user clicks the generate name button.
I have a regular expression that returns multiple matches. For e.g. If the user types a string "980ee,34223,werw" in a textbox, the regular expression match returns "ee" and "werw". I would like to highlight both "ee" and "werw" in the textbox.
What I am trying to do is build a script that will read through an array of words and compare another word to the list to find where it would be placed alphabetically; between which two words would my word go.
Here is what I have come up with so far which doesn't work with words shorter than the shortest word in my list, or words spelled like the shortest word in my list except having a few more characters, plus more various issues.
Example: My list
If I use keywords "apex," or "as", this script fails.
I have a set of regular expressions that make heavy use of the | operator on sections that I do not really need to extract a match from. For example:
Code: var regexp = /([A-Z][A-Za-z]+) (jumps( high)?|leaps|bounds) over ([A-Z][A-Za-z]+) and (grabs|snags|gets) (a|an|the) (apple|orange|pear|grapes)/
The important part for extracting from the match array after using regexp.exec() are the names (the ([A-Z][A-Za-z]+) parts), I don't care which of the other things are matched. The problem is that using the | operator seems to necessitate using the () and adding a term to the match. This makes it difficult to know which term in the array will be the names, especially after editing the middle.So I'd like to be able to use the | operator on words and phrases without adding terms to the match array.
this string will evaluate to a 2D array if I do this:var array = eval(string);But eval is not very safe.Is there a way to achieve the same effect (turn that string into 2d array) without using eval function?And I have no control over what string I am given, so will have to process this kind of a string =Right now I am thinking of writing a custom function which will split the string and then split again etc, but is there already something that can do this job?
how to accomplish this. In my website, I would like the user to input text into a single or multiple textbox(es) and then have the contents of the textbox(es) stored to either a variable or an array. Then I would like to have that variable/array compared to other arrays. Basically, the user is searching for items in a database. The user can search for as many or as little items as they want. Then the item(s) will be compared to multiple arrays to find out if what the user wants is in the database.
So for example, let's say the user is searching for recipes that have all or part of these ingredients: chicken, broccoli, lemon, honey. So, there would have been a total of 4 textboxes...one for each ingredient. These ingredients are stored to an array..lets call it ingredient(). In the database of recipes, each recipe has its own array which includes the ingredients needed to make the recipe, we'll call them tag1(), tag2(), and tag3(). Now, I want the array, ingredient(), to be compared to each of the "tag" arrays to see if any of the "tag" arrays include exactly match the ingredient() tag in part or in whole. Is this possible?