Closed Thread Icon

Topic awaiting preservation: A simple JavaScript question (Page 1 of 1) Pages that link to <a href="http://ozoneasylum.com/backlink?for=21588" title="Pages that link to Topic awaiting preservation: A simple JavaScript question (Page 1 of 1)" rel="nofollow" >Topic awaiting preservation: A simple JavaScript question <span class="small">(Page 1 of 1)</span>\

 
Kalan m
Nervous Wreck (II) Inmate

From: stirling, ON Can.
Insane since: Feb 2004

posted posted 04-29-2004 00:57

The topic today is the string operator 'indexOf()'

As I understand, depending on whether the specified character (or set of characters) are found within the string an integer is returned indicating either true or false (-1, or 1? -this is my question)
if the specified character is found and occurs more than once with indexOf() return the number of times it occured or just '1' indicating that it is true that 'whatever' did occur.

example -

function mine(){

mystring = "My name is Kalan, yes, Kalan is my name";
if(mystring.indexOf("K")==2)
{
alert("There are two 'K' s in the sentence");
}
else{
return false;
}
}

Kalan

poi
Paranoid (IV) Inmate

From: France
Insane since: Jun 2002

posted posted 04-29-2004 01:46

Kalan m: I fear that you misunderstoud the indexOf() method. It returns the position of the first occurence of a substring within a string and -1 if there's none.

The 3rd example in the page I gave you use the indexOf() method in a loop to counts the number of occurences of a subtring within a string.

Regarding your question in pharenthesis, 0 is interpreted as FALSE, and any other value is interpreted as TRUE ( though TRUE is 'normally' expressed by the value 1 in JavaScript ).

Kalan m
Nervous Wreck (II) Inmate

From: Stirling, ON Can.
Insane since: Feb 2004

posted posted 04-30-2004 00:03

Thanks alot poi for clearing that up , it appears as though there is always more to learn, and if not

than you learn that what you thought you knew wasn't right.

Kalan

« BackwardsOnwards »

Show Forum Drop Down Menu