Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

string methods and pre-defined functions 2

Status
Not open for further replies.

theEclipse

Programmer
Dec 27, 1999
1,190
US
There are many string methods, and I would like to know how some of them work. for example<br><br>string.indexOf(something)<br><br>I understand this, but this is where i get confused:<br><br>string.indexOf(something,somethingelse)<br><br>also, are there other string methods that have more than one use?<br><br>thanks <p>theEclipse<br><a href=mailto:eclipse_web@hotmail.com>eclipse_web@hotmail.com</a><br><a href=robacarp.webjump.com>robacarp.webjump.com</a><br>**-Trying to build a documentation of a Javascript DOM, crossbrowser, of course. E-mail me if you know of any little known events and/or methods, etc.
 
<br>From <A HREF=" TARGET="_new"> the index within the calling String object of the first occurrence of the specified value, starting the search at fromIndex, or -1 if the value is not found.<br>Method of<br>&nbsp;String<br>&nbsp;<br>Implemented in<br>&nbsp;Navigator 2.0, LiveWire 1.0<br>&nbsp;<br>Syntax<br>indexOf(searchValue, fromIndex)<br>Parameters<br>searchValue<br>&nbsp;A string representing the value to search for.<br>&nbsp;<br>fromIndex<br>&nbsp;(Optional) The location within the calling string to start the search from. It can be any integer between 0 and 1 less than the length of the string. The default value is 0. <br><br>Hope this helps<br>-pete
 
If you go to <A HREF=" TARGET="_new"> they have several tutorials on Regular Expressions. These are scary, usually unnecessary but very powerful things to understand. If you need functions to work with strings, use them.<br><br>Of course there is also the replace funtion which works with regexps and normal strings like so:<br>str = str.replace(&quot;achar&quot;,&quot;withanotherchar&quot;) (if i recall, if that doesn't work lemme know and ill post the correct code)<br><br><A HREF="mailto:jared@aauser.com">jared@aauser.com</A>
 
Dear jaredn,<br><br>&gt; str = str.replace(&quot;achar&quot;,&quot;withanotherchar&quot;) <br><br>I don't believe that will work for you. The String.replace() method requries a regualar expression as the first argument.<br><br>&gt; These are scary<br><br>Not so scary, more like 'another language'. The real problem is that there is no standard so when you jump from one implementation to another there are some if not many differences.<br><br>&quot;But, that's just my opinion... I could be wrong&quot;.<br>-pete
 
substring() also has more than one use...<br><br>myString = &quot;abcdef&quot;;<br>yourString = myString.substring(2);<br><br>yourString is equal to &quot;cdef&quot; (I think). Basically, from the number you supply (starting at 0) until the end of the string.<br><br>yourString = myString.substring(2, 4);<br><br>yourString in this case is equal to &quot;cde&quot;... does that make sense?<br><br>lastIndexOf() works the same way as indexOf(), except (of course) in the opposite order. <p>Liam Morley<br><a href=mailto:lmorley@wpi.edu>lmorley@wpi.edu</a><br><a href=] :: imotic :: website :: [</a><br>"light the deep, and bring silence to the world.<br>
light the world, and bring depth to the silence.
 
Hey thanks guys!<br><br>You have expanded my knoweladge of javascript<br><br>ô¿ô<br>(-)<br><br>I will also be sure to check out those links<br><br> <p>theEclipse<br><a href=mailto:eclipse_web@hotmail.com>eclipse_web@hotmail.com</a><br><a href=robacarp.webjump.com>robacarp.webjump.com</a><br>**-Trying to build a documentation of a Javascript DOM, crossbrowser, of course. E-mail me if you know of any little known events and/or methods, etc.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top