473,324 Members | 2,254 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,324 software developers and data experts.

How to dinamically change the string in a find statement?

I have a script that opens a small window containing a button which
when clicked performs a find to the next occurence of a string. It
works well when the string is made of only one word or of consecutive
words.
Now I want it to find the next occurence of one of the words contained
in a list, ie. I want to dynamically change the string to find.
I failed to use a regular expression instead of a string in the find
statement.
Any idea of how I can do that?
Thanks.
Jul 23 '05 #1
4 1415
Yv*****************@bull.net (Yves-Alain NICOLLET) wrote in message news:<72**************************@posting.google. com>...
I have a script that opens a small window containing a button which
when clicked performs a find to the next occurence of a string. It
works well when the string is made of only one word or of consecutive
words.
Now I want it to find the next occurence of one of the words contained
in a list, ie. I want to dynamically change the string to find.
I failed to use a regular expression instead of a string in the find
statement.
Any idea of how I can do that?
Thanks.


To make myself clearer, is there a way to say:

find(a_word OR another_word OR yet_another_word OR etc) ?
Jul 23 '05 #2
Yves-Alain NICOLLET wrote:
Yv*****************@bull.net (Yves-Alain NICOLLET) wrote in message
news:<72**************************@posting.google. com>...


Please do not write attribution novels.
I have a script that opens a small window containing a button
Note the security restrictions for the window size:

http://devedge.netscape.com/manuals/2000/javascript/1.3/reference/window.html#1202731>
[...] Now I want it to find the next occurence of one of
the words contained in a list, ie. I want to dynamically change the
string to find. I failed to use a regular expression instead of a
string in the find statement. Any idea of how I can do that? Thanks.


To make myself clearer, is there a way to say:

find(a_word OR another_word OR yet_another_word OR etc) ?


Depends. There is the proprietary window.find() method which
returns `true' if unsuccessful, `false' otherwise. So you can
do consecutive searches:

function findWords()
{
var t;
if ((t = typeof window.find) == "function"
|| (t == object && window.find != null))
{
for (var i = 0, len = arguments.length; i < len; i++)
{
var s = arguments[i];
if (window.find(s))
{
return true; // or s if you like
}
}
}

return false; // no match
}

if (!findWords("a_word", "another_word", "yet_another_word", "etc"))
{
alert("No match for either"
+ "'a_word', 'another_word', 'yet_another_word' or 'etc'");
}

If you want two or more words to be matched and to be selected at
the same time, you need to parse the documents content. Dirty
proprietary quickhack:

document.body.innerHTML.replace(
/(a_word|another_word|yet_another_word|etc)/g,
'<span style="background-color:yellow; color:black">$1</span>');
HTH

PointedEars
Jul 23 '05 #3
Thomas 'Ingrid' Lahn wrote:
[...] There is the proprietary window.find() method which
returns `true' if unsuccessful, `false' otherwise. [...]


returns `true' if successful, `false' otherwise. [...]
PointedEars
Jul 23 '05 #4
Thomas 'Ingrid' Lahn wrote:
If you want two or more words to be matched and to be selected at
the same time, you need to parse the documents content. Dirty
proprietary quickhack:

document.body.innerHTML.replace(
/(a_word|another_word|yet_another_word|etc)/g,
'<span style="background-color:yellow; color:black">$1</span>');


This changes nothing really and "must be" "of course"[1]

document.body.innerHTML = document.body.innerHTML.replace(
/(a_word|another_word|yet_another_word|etc)/g,
'<span style="background-color:yellow; color:black">$1</span>');
PointedEars
___________
[1] Note it is still an evil quickhack.
Jul 23 '05 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
by: Richard Cornford | last post by:
For the last couple of months I have been trying to get the next round of updates to the FAQ underway and been being thwarted by a heavy workload (the project I am working on has to be finished an...
2
by: Daniel | last post by:
Hello!!! I'm creating controls dinamically in ASP.NET using VB. The problem is that i don't know how to catch the event of each button that i've create (the buttons are created dinamically). ...
2
by: Marco | last post by:
How I can create TextBox dinamically. I have to create 10 textbox dinamically which name will be txtBox_01, txtBox_02, etc... Thanks.
2
by: Fabio Cavassini | last post by:
I have this code that load HTML tags (no including <html> or <body>) into a DIV dinamically... after correctly retrieving the HTML, I assign it to my DIV Container ...
32
by: Mateo | last post by:
I have char *array and it is dinamically alocated.... When I pass it to other function, I need to determine size of this array.... Problem: sizeof operator does not work with dinamically alocated...
3
by: valerio | last post by:
Hello all I would like to dinamically allocate an array of array of structures. To explain this: struct file{ char* fileName,int inode) myfiles; struct file{ char* fileName,int inode) mydirs; ...
0
by: Chepre | last post by:
Hi, I've the following problem. I load an assembly dinamically through code, but I can't call the method GetCredentials correctly, it's allways null. Assembly assem =...
0
by: DiegoBernini | last post by:
I have two assembly written in Managed C++ (VS2005) CdWrapperApi.dll, "contains" namespace CDWrapperApi { ... public interface class ICDProxy { public:
5
by: srcp | last post by:
I got a table with for example 10 fields, field001, field002 ...field010 what i want is do something like this For i As Integer = 1 To 10 (table.field00 & i).value = "XX" Next i any ideas??
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.