Filtering words - 2nd post 
Author Message
 Filtering words - 2nd post

Let me try this again.  Let's just say I want to filter the words "rainbow"
and "sunshine" from a string.  If I do this, it works:

M_getMessage = M_getMessage(/rainbow/g, "****);

It filters rainbow perfectly.  Now, since there are a few words, and I'd
like to add more later, I decided to make an array:

M_array = new Array("rainbow", "sunshine");

for(x = 0 ; x < M_array.length ; x++)
{
    M_getMessage = M_getMessage(/M_array[x]/g, "***");

Quote:
}

No errors are generated, but it doesn't filter my words.

I've even tried converting the array element to a string, and using that,
but it still doesn't work.

Any ideas on what I'm doing wrong?

Thanks,

Matt



Tue, 24 Sep 2002 03:00:00 GMT  
 Filtering words - 2nd post
Hi Matthew

Quote:

> M_array = new Array("rainbow", "sunshine");

> for(x = 0 ; x < M_array.length ; x++)
> {
>     M_getMessage = M_getMessage(/M_array[x]/g, "***");
> }

I have not tested it, but it should work:

   M_getMessage = eval('M_getMessage(/' + M_array[x] + '/g, "***")');

Hope this helps.
Klaus



Tue, 24 Sep 2002 03:00:00 GMT  
 Filtering words - 2nd post
It worked perfectly!  Thanks.  Just out of curiosity though, what's the
logic behind it?  I know what everything does, but I don't know how they
apply in this situation.

Thanks again,

Matt



Quote:
> Hi Matthew


> > M_array = new Array("rainbow", "sunshine");

> > for(x = 0 ; x < M_array.length ; x++)
> > {
> >     M_getMessage = M_getMessage(/M_array[x]/g, "***");
> > }

> I have not tested it, but it should work:

>    M_getMessage = eval('M_getMessage(/' + M_array[x] + '/g, "***")');

> Hope this helps.
> Klaus



Tue, 24 Sep 2002 03:00:00 GMT  
 Filtering words - 2nd post
Your regular expression is looking for the string "M_array[x]". The /'s are
RegExp delimiters just like " or ' are string delimiters. If you only have
to filter two words you could use the RegExp or operator (|):

  M_getMessage = M_getMessage.replace(/rainbow|sunshine/ig,"***"));

If you need to filter a larger list, you can create a RegExp object for each
item in the list:

  M_array = new Array("rainbow", "sunshine");

  for(x = 0 ; x < M_array.length ; x++)
  {
    var re = new RegExp(M_array[x], "ig");
    M_getMessage = M_getMessage.replace(re, "***");
  }

=-=-=
Steve
-=-=-


Quote:
> Let me try this again.  Let's just say I want to filter the words
"rainbow"
> and "sunshine" from a string.  If I do this, it works:

> M_getMessage = M_getMessage(/rainbow/g, "****);

> It filters rainbow perfectly.  Now, since there are a few words, and I'd
> like to add more later, I decided to make an array:

> M_array = new Array("rainbow", "sunshine");

> for(x = 0 ; x < M_array.length ; x++)
> {
>     M_getMessage = M_getMessage(/M_array[x]/g, "***");
> }

> No errors are generated, but it doesn't filter my words.

> I've even tried converting the array element to a string, and using that,
> but it still doesn't work.

> Any ideas on what I'm doing wrong?

> Thanks,

> Matt



Tue, 24 Sep 2002 03:00:00 GMT  
 
 [ 4 post ] 

 Relevant Pages 

1. 2nd Post: IFRAME DIVs and form fields

2. 2nd post - Stopping a service

3. showModalDialog not returning any value....2nd post.

4. require form before dowload - 2nd post

5. Line Break - 2nd Post

6. 2nd Post: IFRAME DIVs and form fields

7. 2nd Post: Programmatically controlling printing...

8. 2nd Post - AT Jobs not starting WSHs

9. HP4MV printer banner page(2nd post)

10. Obfuscated PostScript contest (2nd posting)

11. Print Booklets with Word for Windows without Paste-up (2nd try)

12. Post-Script Filters

 

 
Powered by phpBB® Forum Software