SitePoint Sponsor

User Tag List

Results 1 to 9 of 9
  1. #1
    SitePoint Evangelist -T-'s Avatar
    Join Date
    Jun 2002
    Posts
    444
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    substring(1,2)??

    what does that do??

    and is there a javascript manual out there that I can look up function in?
    chrome is a wrapper that combines a browser with spyware

  2. #2
    Non-Member QualityWebHosts's Avatar
    Join Date
    Sep 2003
    Location
    USA
    Posts
    45
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Here's an example of how it is used:
    // The three lines below checks if a target goes along with the URL
    // That is: (if a "&" is in the option-value).
    // If so, the URL is stored in a variable called loc and the target
    // is stored in a variable called target.
    // If not the URL is stored in a variable called loc and "_self" is
    // stored in the variable called target.
    if (splitcharacter!=-1) {loc=ref.substring(0,splitcharacter); target=ref.substring(splitcharacter+1,1000).toLowerCase();}
    else {loc=ref; target="_self";};

  3. #3
    SitePoint Evangelist -T-'s Avatar
    Join Date
    Jun 2002
    Posts
    444
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    thanks
    chrome is a wrapper that combines a browser with spyware

  4. #4
    Web-coding NINJA! silver trophy beetle's Avatar
    Join Date
    Jul 2002
    Location
    Dallas, TX
    Posts
    2,900
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    More to the point.

    String.substring() takes two arguments. The first argument is the length-index of the first character to be returned. The 2nd argument is the length-index up to which substring() copies. The character at this index is not returned.

    1) If no 2nd argument is given, substring() copies to the end of the string
    2) If argument 2 is greater than argument 1, substring() will simply go backwards.

    When I say length-index, I referring to the fact that strings have a length, and each character is accessible by a zero-based index.
    Code:
    string:   "string"
    indicies: 012345
    As you can see, the first letter is 0, and the indicies count up from there.

    This means:
    string.charAt(1) will return t
    string.substring(3) will return ing
    string.substring(2,4) will return ri
    string.substring(4,2) will return ri

    You can look this sort of stuff up online.
    Microsoft JScript reference
    Netscape Javascript reference

    There are only minor discrepancies between the two implementations, so either reference should suffice for most things.
    beetle a.k.a. Peter Bailey
    blogs: php | prophp | security | design | zen | software
    refs: dhtml | gecko | prototype | phpdocs | unicode | charsets
    tools: ide | ftp | regex | ffdev




  5. #5
    "Of" != "Have" bronze trophy Jeff Lange's Avatar
    Join Date
    Jan 2003
    Location
    Calgary, Canada
    Posts
    2,063
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Sorry to correct the Javascript Guru, but when 2 arguments are provided, the second one sets the length to return, starting from the index provided in the first argument:

    string.substring(2,4) will return ring
    string.substring(4,2) will return ng

    edit:I'm retarded. I posted information about substr() not substring(). Sorry
    Last edited by Jeff Lange; Oct 3, 2003 at 14:00.
    Who walks the stairs without a care
    It shoots so high in the sky.
    Bounce up and down just like a clown.
    Everyone knows its Slinky.

  6. #6
    Web-coding NINJA! silver trophy beetle's Avatar
    Join Date
    Jul 2002
    Location
    Dallas, TX
    Posts
    2,900
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Um, I hardly think so.
    Quote Originally Posted by MSDN
    The length of the substring is equal to the absolute value of the difference between start and end.
    Did you even try testing your example before posting?

    You are clearly confusing String.substring() with String.substr().
    beetle a.k.a. Peter Bailey
    blogs: php | prophp | security | design | zen | software
    refs: dhtml | gecko | prototype | phpdocs | unicode | charsets
    tools: ide | ftp | regex | ffdev




  7. #7
    "Of" != "Have" bronze trophy Jeff Lange's Avatar
    Join Date
    Jan 2003
    Location
    Calgary, Canada
    Posts
    2,063
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Looks like I edited my post before you posted that one.

    Sorry, lol, I should have known better
    Who walks the stairs without a care
    It shoots so high in the sky.
    Bounce up and down just like a clown.
    Everyone knows its Slinky.

  8. #8
    Web-coding NINJA! silver trophy beetle's Avatar
    Join Date
    Jul 2002
    Location
    Dallas, TX
    Posts
    2,900
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    No prob, bro
    beetle a.k.a. Peter Bailey
    blogs: php | prophp | security | design | zen | software
    refs: dhtml | gecko | prototype | phpdocs | unicode | charsets
    tools: ide | ftp | regex | ffdev




  9. #9
    The doctor is in... silver trophy MarcusJT's Avatar
    Join Date
    Jan 2002
    Location
    London
    Posts
    3,509
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by Jeff Lange
    Looks like I edited my post before you posted that one.

    Sorry, lol, I should have known better
    Don't mess with greatness...
    MarcusJT
    - former ASP web developer / former SPF "ASP Guru"
    - *very* old blog with some useful ASP code

    - Please think, Google, and search these forums before posting!


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •