I know it is related to Remove first character from a string if it is a comma but in this case that solution doesn't work for me. Maybe its because now I'm dealing with a number. Simply I want javascript to remove 0
from 08
but don't touch 10
; only remove 0
when it is the first character.
This solution doesn't work: replace(/^0/, "")
You can remove the first character of a string using substring: var s1 = "foobar"; var s2 = s1.substring (1); alert (s2); // shows "oobar" var s = "0000test"; while (s.charAt (0) === '0') { s = s.substring (1); }
The deleteCharAt () method accepts a parameter as an index of the character you want to remove. Remove last character of a string using sb.deleteCharAt (str.length () – 1). Remove first character of a string using sb.deleteCharAt (0). Now, print the modified string.
Algorithm: Let the first input string be a ”test string” and the string which has characters to be removed from the first string be a “mask” Construct count array from mask_str. The count array would be:
Some start in 0 and some don't. For the ones that start in 0 I would like to remove the 0. Find and replace wouldnt work as some of the numbers have a 0 at other positions in the number. How can I removed the first character if it is an 0? =A1+0 will remove leading zeros, if the cell holding the formula is formatted General.
You can try this:
alert("08".replace(/^0+/, ''));
DEMO
And if you are dealing with numbers then you can use parseInt() function.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With