What happened to the Messenger Plus! forums on msghelp.net?
Shoutbox » MsgHelp Archive » Messenger Plus! for Live Messenger » Scripting » Several Questions...

Several Questions...
Author: Message:
CookieRevised
Elite Member
*****

Avatar

Posts: 15517
Reputation: 173
– / Male / Flag
Joined: Jul 2003
Status: Away
RE: Several Questions...
quote:
Originally posted by Huhu_Manix
You can use indexOf() for find a word too.

And for the substring, the good syntax is :
code:
var a = "abc";
var b = a.substring(1);

(...)

I give him only the good syntax of substring...

But ".substr()" work too ? ^o)
There is no 'good' and 'wrong' syntax.

substr and substring are two different functions. They do not work the same way. Each has his own specific uses.

quote:
Originally posted by deAd
code:
var sSubString = sString.substr(1,3); // The first parameter is the index to start at. It is zero-based. The second is how many characters to include. If you leave out the second, it will just cut off however many characters you specify in the first parameter.

nope... leaving out the second parameter will not cut off anything; it will return the remainder of the whole string.


-------------------------

Syntax: stringvar.substr(start [, length ])
  • stringvar
    Required.
    A string literal or String object from which the substring is extracted.

  • start
    Required.
    The zero-based starting position of the desired substring.

  • length
    Optional.
    The number of characters to include in the returned substring.

    If zero or negative, an empty string is returned.
    If not specified, the substring continues to the end of stringvar.

  • Example
    var s = "The rain in Spain falls mainly in the plain.";
    return s.substr(12, 5); // Returns "Spain".
    return s.substr(24);     // Returns "mainly in the plain.".

Syntax: stringvar.substring(start, end)
  • stringvar
    Required.
    A string literal or String object from which the substring is extracted.

  • start
    Required.
    The zero-based starting position of the desired substring.

  • end
    Required.
    The zero-based position indicating the end of the substring.

  • Remarks
    The substring method returns a string containing the substring from start up to, but not including, end.

    The substring method uses the lowest value of start and end as the beginning point of the substring. For example, strvar.substring(0, 3) and strvar.substring(3, 0) return the same substring.

    If either start or end is NaN or negative, it is replaced with zero.

    The length of the substring is equal to the absolute value of the difference between start and end. For example, the length of the substring returned in strvar.substring(0, 3) and strvar.substring(3, 0) is 3.

  • Example
    var s = "The rain in Spain falls mainly in the plain..";
    return s.substring(12, 17); // Returns "Spain".
    return s.substring(17, 12); // Returns "Spain".
    return s.substring(-10, 3); // Returns "The".


---------

In this post, you can see the 3 practical and different examples of the different uses:
CookieRevised's reply to "[I help them] VB2JS":
quote:
Snippet from original posting from CookieRevised
// Returns a string containing a specified number of characters from the left side of a string.
function Left(s, length) { return s.substring(0, length) }

// Returns a string containing a specified number of characters from the right side of a string.
function Right(s, length) { return s.substr(s.length-length) }

// Returns a string containing a specified number of characters from a string (length parameter is optional).
function Mid(s, start, length) { return s.substr(--start, length) }
Left() uses the substring method
Right() uses the substr method
Mid() uses the substr method with optional length parameter.






This post was edited on 09-17-2006 at 01:51 AM by CookieRevised.
.-= A 'frrrrrrrituurrr' for Wacky =-.
09-17-2006 01:29 AM
Profile PM Find Quote Report
« Next Oldest Return to Top Next Newest »

Messages In This Thread
Several Questions... - by Robin4286 on 09-15-2006 at 10:39 PM
RE: Several Questions... - by cloudhunter on 09-15-2006 at 10:44 PM
RE: Several Questions... - by Robin4286 on 09-15-2006 at 11:04 PM
RE: Several Questions... - by Spunky on 09-15-2006 at 11:08 PM
RE: Several Questions... - by Huhu_Manix on 09-15-2006 at 11:24 PM
RE: Several Questions... - by deAd on 09-15-2006 at 11:28 PM
RE: Several Questions... - by Huhu_Manix on 09-15-2006 at 11:39 PM
RE: Several Questions... - by markee on 09-16-2006 at 07:09 AM
RE: Several Questions... - by CookieRevised on 09-17-2006 at 01:29 AM
RE: RE: Several Questions... - by Huhu_Manix on 09-17-2006 at 12:37 PM
RE: Several Questions... - by deAd on 09-17-2006 at 01:34 PM
RE: Several Questions... - by Huhu_Manix on 09-17-2006 at 01:55 PM


Threaded Mode | Linear Mode
View a Printable Version
Send this Thread to a Friend
Subscribe | Add to Favorites
Rate This Thread:

Forum Jump:

Forum Rules:
You cannot post new threads
You cannot post replies
You cannot post attachments
You can edit your posts
HTML is Off
myCode is On
Smilies are On
[img] Code is On