www.webdeveloper.com
Results 1 to 3 of 3

Thread: Remove the last 16 digits at the end of text

Hybrid View

  1. #1
    Join Date
    Mar 2006
    Posts
    58

    Remove the last 16 digits at the end of text

    I have a string that looks like this:
    Code:
    [APPLE PIE] Sei Shoujo Sentai Lakers 3 Battle Team Lakers 3 (100% FULL-PIC)_20121104_032834
    I want to remove the digits at the end of the string, basically the 16 digits at the end of the string. In the end it should look like this:
    Code:
    [APPLE PIE] Sei Shoujo Sentai Lakers 3 Battle Team Lakers 3 (100% FULL-PIC)
    This is my code that I have written so far
    Code:
    var str="[APPLE PIE] Sei Shoujo Sentai Lakers 3 Battle Team Lakers 3 (100% FULL-PIC)_20121104_032834";
    var n=str.substr(1,74);
    document.write(n);
    The problem is the string will be different so each will have different amount of characters. So how I remove the digits at the end of the string in javascript?

  2. #2
    Join Date
    Mar 2007
    Location
    U.K.
    Posts
    1,127
    This is a multi-posted question and the spammer has had his answer already.

  3. #3
    Join Date
    Oct 2010
    Location
    Versailles, France
    Posts
    1,276
    Use str.substr(0,str.length-16) or a regular expression like this following which remove 16 (the number in curly brackets) digits or underscore (\d for a digit and _ in the square brackets) a the end (the $) of a string
    Code:
    var n=str.replace(/[\d_]{16}$/,'');
    Last edited by 007Julien; 11-26-2012 at 11:57 AM.

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

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



Recent Articles