#500 enhancement
Xanadu

String#explode

Reported by Xanadu | December 22nd, 2008 @ 11:52 AM

The standard JS String#split method is useful, but has flaws in my opinion.


var str="How are you doing today?";
str.split(" ", 3); // -> ['How','are','you']

A new explode method should work similar to split, but would return a concatenation of the last items (similar to it's PHP equivalent).


var str="How are you doing today?";
str.explode(" ", 3); // -> ['How','are','you doing today?']

Without the second parameter it would be behave the way split does.

Sources: * W3Schools * PHP explode

Comments and changes to this ticket

  • Juriy Zaytsev

    Juriy Zaytsev December 22nd, 2008 @ 01:12 PM

    split doesn't have flaws; it was just designed differently.

    I suppose something like this should do it (untested), although I personally don't think it's a worthy addition to the core.

    
    String.prototype.explode = function(separator, count) {
      var r = this.split(separator);
      if (typeof count != 'undefined') {
        var ending = r.slice(count-1).join(separator);
        r.length = count;
        r[count-1] = ending;
      }
      return r;
    };
    
  • Tobie Langel

    Tobie Langel December 23rd, 2008 @ 02:01 AM

    • State changed from “new” to “enhancement”
  • Samuel Lebeau

    Samuel Lebeau December 23rd, 2008 @ 11:50 PM

    • Tag set to needs_docs, needs_patch, needs_tests

    @Juriy: agreed, not for core IMHO.

  • Tobie Langel

    Tobie Langel July 24th, 2009 @ 02:25 AM

    • Tag changed from needs_docs, needs_patch, needs_tests to missing:documentation, needs_patch, needs_tests

    [not-tagged:"needs_docs" tagged:"missing:documentation" bulk edit command]

  • Tobie Langel

    Tobie Langel July 24th, 2009 @ 02:26 AM

    • Tag changed from missing:documentation, needs_patch, needs_tests to missing:documentation, missing:tests, needs_patch

    [not-tagged:"needs_tests" tagged:"missing:tests" bulk edit command]

  • Tobie Langel

    Tobie Langel July 24th, 2009 @ 02:28 AM

    • Tag changed from missing:documentation, missing:tests, needs_patch to missing:documentation, missing:patch, missing:tests

    [not-tagged:"needs_patch" tagged:"missing:patch" bulk edit command]

  • Tobie Langel

    Tobie Langel July 24th, 2009 @ 03:36 AM

    • Tag changed from missing:documentation, missing:patch, missing:tests to missing:documentation, missing:patch, needs:tests

    [not-tagged:"missing:tests" tagged:"needs:tests" bulk edit command]

  • Tobie Langel

    Tobie Langel July 24th, 2009 @ 03:37 AM

    • Tag changed from missing:documentation, missing:patch, needs:tests to missing:documentation, needs:patch, needs:tests

    [not-tagged:"missing:patch" tagged:"needs:patch" bulk edit command]

  • Tobie Langel

    Tobie Langel July 24th, 2009 @ 03:38 AM

    • Tag changed from missing:documentation, needs:patch, needs:tests to needs:doc, needs:patch, needs:tests

    [not-tagged:"missing:documentation" tagged:"needs:doc" bulk edit command]

  • T.J. Crowder

    T.J. Crowder November 16th, 2009 @ 04:50 PM

    [responsible:none bulk edit command]

  • Tobie Langel

    Tobie Langel March 1st, 2010 @ 01:25 AM

    • Tag changed from needs:doc, needs:patch, needs:tests to needs:doc, needs:patch, needs:tests, section:lang

Please Sign in or create a free account to add a new ticket.

With your very own profile, you can contribute to projects, track your activity, watch tickets, receive and update tickets through your email and much more.

New-ticket Create new ticket

Create your profile

Help contribute to this project by taking a few moments to create your personal profile. Create your profile ยป

The Prototype JavaScript library.

Shared Ticket Bins

People watching this ticket

Pages