Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 5 of 5
  1. #1
    New Coder
    Join Date
    Sep 2012
    Posts
    79
    Thanks
    2
    Thanked 1 Time in 1 Post

    [solved] wrong text string length

    here's how the string comes to existence:

    Code:
     presidentsname = ((lista[number]).split("|")).slice(0,1);
    
     document.diagnostic.window1.value=presidentsname+"    " +presidentsname.length;
    with Hollande the name shows properly, but the length turns out to be 1

    how to modify presidentsname.length in order to obtain 8?

    or must the error be elsewhere?
    Last edited by eydg; 04-22-2013 at 11:27 AM.

  • #2
    Supreme Master coder! glenngv's Avatar
    Join Date
    Jun 2002
    Location
    Philippines
    Posts
    10,968
    Thanks
    0
    Thanked 236 Times in 233 Posts
    presidentsname is an array with a single element "Hollande". That's why presidentsname.length returns 1.

  • #3
    Senior Coder jmrker's Avatar
    Join Date
    Aug 2006
    Location
    FL
    Posts
    3,032
    Thanks
    36
    Thanked 495 Times in 489 Posts
    Answered while typing.

    Sorry for slowness

  • #4
    New Coder
    Join Date
    Sep 2012
    Posts
    79
    Thanks
    2
    Thanked 1 Time in 1 Post
    But how to squeeze the number of letters out of such an array, anyway?

    edit:

    here is the answer:
    presidentsname[0].length

    Thank you!
    Last edited by eydg; 04-22-2013 at 11:27 AM.

  • #5
    Supreme Master coder! Philip M's Avatar
    Join Date
    Jun 2002
    Location
    London, England
    Posts
    17,734
    Thanks
    202
    Thanked 2,508 Times in 2,486 Posts
    Quote Originally Posted by eydg View Post
    But how to squeeze the number of letters out of such an array, anyway?
    Code:
    var presidentsname = ["Hollande", "Mitterand", "de Gaulle"]
    alert (presidentsname[0].length);  // 8
    alert (presidentsname[1].length);  // 9
    It is your responsibility to die() if necessary….. - PHP Manual

    All the code given in this post has been tested and is intended to address the question asked.
    Unless stated otherwise it is not just a demonstration.


  •  

    Posting Permissions

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