How to remove leading and trailing zeros in a string? Python

What about a basic your_string.strip(“0”) to remove both trailing and leading zeros ? If you’re only interested in removing trailing zeros, use .rstrip instead (and .lstrip for only the leading ones). More info in the doc. You could use some list comprehension to get the sequences you want like so: trailing_removed = [s.rstrip(“0”) for s … Read more

How to concatenate strings with padding in sqlite

The || operator is “concatenate” – it joins together the two strings of its operands. From http://www.sqlite.org/lang_expr.html For padding, the seemingly-cheater way I’ve used is to start with your target string, say ‘0000’, concatenate ‘0000423’, then substr(result, -4, 4) for ‘0423’. Update: Looks like there is no native implementation of “lpad” or “rpad” in SQLite, … Read more

Javascript add leading zeroes to date

Try this: http://jsfiddle.net/xA5B7/ var MyDate = new Date(); var MyDateString; MyDate.setDate(MyDate.getDate() + 20); MyDateString = (‘0’ + MyDate.getDate()).slice(-2) + “https://stackoverflow.com/” + (‘0’ + (MyDate.getMonth()+1)).slice(-2) + “https://stackoverflow.com/” + MyDate.getFullYear(); EDIT: To explain, .slice(-2) gives us the last two characters of the string. So no matter what, we can add “0” to the day or month, and … Read more