Searching through a string

Nov 5, 2007 at 3:04am

Searching through a string

Hi all:

I’ve been trying to get the following search script to work, but I get
“inputString.search is not a function”. What am I doing wrong?

—-BEGIN SCRIPT—-
function anything()
{
var pattern=/href/;
inputString = arrayfromargs(messagename, arguments);
post(“LENGTH IS ” + inputString.length);
for (var i=0; i
if (inputString.search(pattern)){
outputString=”There it is!”;
}
else{
outputString = “Sorry, not here!”;
}
}
bang();
}
—-END SCRIPT—-

Thanks in advance,

-R

#34461
Nov 5, 2007 at 3:12am

inputString is an array in your code. Perhaps you need to do
inputString[i].search(pattern).

wes

On 11/4/07, lists@zdomain.net

wrote:
> Hi all:
>
> I’ve been trying to get the following search script to work, but I get
> “inputString.search is not a function”. What am I doing wrong?
>
> —-BEGIN SCRIPT—-
> function anything()
> {
> var pattern=/href/;
> inputString = arrayfromargs(messagename, arguments);
> post(“LENGTH IS ” + inputString.length);
> for (var i=0; i
> if (inputString.search(pattern)){
> outputString=”There it is!”;
> }
> else{
> outputString = “Sorry, not here!”;
> }
> }
> bang();
> }
> —-END SCRIPT—-
>
> Thanks in advance,
>
> -R
>

#116338

Oso
Nov 5, 2007 at 3:36am

Thanks for the reply, Wesley. I was able to get it to work, thanks in
no small part to using your observation!

Here is the working code:

—-BEGIN SCRIPT—-
function anything()
{
var pattern=/sleep/;
inputString = arrayfromargs(messagename, arguments);
post(“LENGTH IS ” + inputString.length);
post(inputString);
for (var i=0; i
if (inputString[i].match(pattern)){
outputString=”There it is!”;
}
else{
outputString = “Sorry, not here!”;
}
}
bang();
}
—-END SCRIPT—-

Best,

-R

Quoting Wesley Smith :

> inputString is an array in your code. Perhaps you need to do
> inputString[i].search(pattern).
>
> wes
>
> On 11/4/07, lists@zdomain.net

wrote:
>> Hi all:
>>
>> I’ve been trying to get the following search script to work, but I get
>> “inputString.search is not a function”. What am I doing wrong?
>>
>> —-BEGIN SCRIPT—-
>> function anything()
>> {
>> var pattern=/href/;
>> inputString = arrayfromargs(messagename, arguments);
>> post(“LENGTH IS ” + inputString.length);
>> for (var i=0; i
>> if (inputString.search(pattern)){
>> outputString=”There it is!”;
>> }
>> else{
>> outputString = “Sorry, not here!”;
>> }
>> }
>> bang();
>> }
>> —-END SCRIPT—-
>>
>> Thanks in advance,
>>
>> -R
>>
>

#116339

You must be logged in to reply to this topic.