SitePoint Sponsor

User Tag List

Results 1 to 2 of 2

Hybrid View

  1. #1
    SitePoint Member
    Join Date
    Jun 2007
    Posts
    10
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    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
    Under Construction silver trophybronze trophy AussieJohn's Avatar
    Join Date
    Sep 2005
    Location
    Sydney, Australia
    Posts
    776
    Mentioned
    11 Post(s)
    Tagged
    0 Thread(s)
    You can, instead of hard coding the length of the substring, use the length of the string minus the # of characters you want to remove.

    so something like this:
    Code javascript:
    var str = "This is a string with some chars at the end 1234567891234567";
    var fixedStr = str.substr(0, str.length-16);
    var details = {
    . . web: "afterlight.com.au",
    . . photos: "jvdl.id.au",
    . . psa: "usethelatestversion.com"
    }


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
  •