How to remove the first symbol from the line?



  • There's a variable that contains the type data. %4820109928069
    How do you remove the percentage symbol so there's only a number?



  • Important: all the following methods: Not Change the line of reference!


    You can use it. https://developer.mozilla.org/en/docs/Web/JavaScript/Reference/Global_Objects/String/slice

    document.body.innerHTML = '%4820109928069'.slice(1);

    or https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/substr

    document.body.innerHTML = '%4820109928069'.substr(1);

    or https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/substring

    document.body.innerHTML = '%4820109928069'.substring(1);

    If you want to end up with it... line numerical and number, should also be used

    https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/parseInt

    document.body.innerHTML = typeof '%4820109928069'.substring(1);
    document.body.innerHTML +='<br/>'+ typeof parseInt('%4820109928069'.substring(1),10);
    document.body.innerHTML +='<br/>'+ parseInt('%4820109928069'.substring(1),10);

    or https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/parseFloat

    document.body.innerHTML = typeof '%4820109928069'.substring(1);
    document.body.innerHTML += '<br/>' + typeof parseFloat('%4820109928069'.substring(1));
    document.body.innerHTML += '<br/>' + parseFloat('%4820109928069'.substring(1));


    Upd.
    Alternative https://developer.mozilla.org/ru/docs/Web/JavaScript/Reference/Global_Objects/String/replace :

    removed % starting line

    document.body.innerHTML = '%4820109928069'.replace(/^%/,'');

    remove everything % in line:

    document.body.innerHTML = '%4820109%928069%'.replace(/%/g,'');

    Remove all non-digital symbols:

    document.body.innerHTML = '%482s01099$280%69zxc_'.replace(/\D/g,'');


Log in to reply
 


Suggested Topics

  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2