Leading zeroes

Hello,

How can I suppress the leading zeroes, except one when all positions are 0;
for example:

000015 will be 15
000000 will be 0

thank you.

Olivier

-- 
+++ GMX - die erste Adresse f�r Mail, Message, More +++
Neu: Preissenkung f�r MMS und FreeMMS! http://www.gmx.net


0
Olivier6
1/10/2004 2:34:39 PM
perl.beginners 29388 articles. 4 followers. Follow

3 Replies
1151 Views

Similar Articles

[PageSpeed] 44
Get it on Google Play
Get it on Apple App Store

Olivier Wirz wrote:
> Hello,
> 
> How can I suppress the leading zeroes, except one when all positions are 0;
> for example:
> 
> 000015 will be 15
> 000000 will be 0

This is a pretty vague question. How are you outputting the numbers? Are you writing to a 
file, using print, using printf, etc.?

-- 
Andrew Gaffney
System Administrator
Skyline Aeronautics, LLC.
776 North Bell Avenue
Chesterfield, MO 63005
636-357-1548

0
agaffney
1/10/2004 3:17:52 PM
On Jan 10, 2004, at 8:34 AM, Olivier Wirz wrote:

> Hello,
>
> How can I suppress the leading zeroes, except one when all positions 
> are 0;
> for example:
>
> 000015 will be 15
> 000000 will be 0

See if this one-liner gets you going:

perl -le 'foreach (@ARGV) { s/^0+([0-9])/$1/; print; }' 000015 000000
15
0

James

0
james
1/10/2004 5:25:51 PM
Olivier Wirz wrote:
> 
> Hello,

Hello,

> How can I suppress the leading zeroes, except one when all positions are 0;
> for example:
> 
> 000015 will be 15
> 000000 will be 0

Just use the "numbers" in a numeric context:

$ perl -le'
for ( "000000", "000015" ) {
    print "String: ", $_;
    print "Number: ", $_ + 0;
    }
'
String: 000000
Number: 0
String: 000015
Number: 15



John
-- 
use Perl;
program
fulfillment
0
krahnj
1/10/2004 9:35:57 PM
Reply:

Similar Artilces:

Autocomplete dropping leading zeros and trailing zeros after a hyphen
Autocomplete Web Service Code 1    Imports System.Web2    Imports System.Web.Services3    Imports System.Web.Services.Protocols4    Imports System.Data.SqlClient5    Imports System.Data6    7    ' To allow this Web Service to be called from script, using ASP.NET AJAX, uncomment the following line.8    <System.Web.Script.Services.ScriptService()> _9    <WebService(Namespace:="http://tempuri.org/")> _10   <WebServiceBindi...

Leading Zero
Does anyone know of a existing problem from inetcfg bind then reinitialize system then the udp/tcp is putting in a leading zero at the third octect ....192.168.0.21 - 192.168.00.21...This is causing a problem of course....Help Gerald Cummings wrote: > Does anyone know of a existing problem from inetcfg bind then reinitialize > system then the udp/tcp is putting in a leading zero at the third octect > ...192.168.0.21 - 192.168.00.21...This is causing a problem of > course....Help Haven't seen that one... what version of netware, service packs, tcp/ip etc? Is...

Leading zeros
How can you place leading zeros on an integer before converting to string? You can't add leading 0's to the integer but why not do..... MyString = "00000" & str(MyInt) Mat Please try the following varStr = string.Format("{0:000000000}",varNum); ThanksSenthil Nathan http://www.chendhur.com Hi Try as below : Dim PadNbr As String = Trim(Str(12345)) Response.Write(PadNbr.PadLeft(Len(PadNbr) + 1, "0")) HTH K B ShajudeenAreYaar.comDubai, United Arab Emirates....

Leading zeros?
I need help with leading zeros within the presentation layer of asp.net. I'm pulling a number from a sql database and display it on a textbox. I want that number to have leading zeros. Example: 149 I want that to be like 00149 or 1234 to be like 01234. I tried several examples provided within some of the previous threads but no luck. Example I use this one: varNum = String.Format("{0:00000}", varStr) Please advise. try something like this : Dim i As Integer, j As String, k As String, val as string i = 123 k = "00000" j = Convert.T...

Leading zero ?!
Hi,I'm using Convert.ToString() method to convert Hour or Minute of a datetime format control to a string but it's not a leading zero string.  How can I do it ?Please help !cheers,stephen   I think you are using the wrong ToString try DateTime.ToString and System.TimeSpan.  Hope this helps.http://msdn2.microsoft.com/en-us/library/system.timespan.aspxhttp://msdn2.microsoft.com/en-us/library/k494fzbf.aspxKind regards,Gift Peddie  By using the DateTime's ToString and with a format expression, you can format the date into a string...

How to add leading zeros?
Hello, I have some Numbers 1 2 3 40 51 and I want them to be in the format 001 002 003 ... 040 ... 051 ... What is the fastest way to do this?? Bastian Angerstein [BA], on Wednesday, February 16, 2005 at 13:28 (+0100) wrote the following: BA> I have some Numbers 1 2 3 40 51 and I want them to be in the format BA> 001 002 003 ... 040 ... 051 ... perldoc -f printf perldoc -f sprintf printf("%03.d", 50); -- ...m8s, cu l8r, Brano. [She wanted a fur coat so he got her a trap and a gun.] Bastian Angerstein wrote: >Hello, > >I...

Removing Leading Zeros
Hi all, I have sucked two substrings into two variables : $index = substr $_, 35, 11; $value = substr $_, 64, 6; These variables may or may not have leading zero/s : 000009/000099/000999........ and so on. If they do I need to strip away the leading zeros. Any ideas? Mark : I have sucked two substrings into two variables : : : $index = substr $_, 35, 11; : $value = substr $_, 64, 6; : : These variables may or may not have leading zero/s : : : 000009/000099/000999........ and so on. : : If they do I need to strip away the leading zeros. A regexp r...

AutoCompleteExtender and leading zeroes
I am using the ajaxToolkit:AutoCompleteExtender in my app. It does work, except for one problem-- if the column read from the database is complsed of digits only, and has leading zeroes    (e.g. "02"),  it strips the leading zero when displaying the column in the drop down. For example, "02" is displayed as "2".   Is there a way to fix this?  ( The column is type CHAR, and   if it contains some alpha characters the extender displays it cor...

Format leading zeros?
How can I format a value to always be seven digits with leading zeros? ie: select number from table where it will come out as: 0000007 0000077 0000777 etc. Thank you. BTW _ I know I can do this with a hefty CASE statement but I was looking for something easier. -Robert "Robert Paresi" <FirstInitialLastName@innquest.com> wrote in message news:470ea531$1@forums-1-dub... > How can I format a value to always be seven digits with leading zeros? > > ie: > > select number from table > > where it will come out as: > ...

Leading zero in a string
Hi All, I have a variable I'm reading off of the command line: my $option = shift; That variable should hold a number between 1 and 31 (yes, a day of the month) I am checking to make sure that the number does indeed lie in that range. However, I need to pass that variable to another system command which expects any "day" value less than 10 to have a leading zero, so 7th day of the month should say '07'. How can I check for that leading zero? If it's missing, I know I could easily: $option = "0".$option; But I can't seem to figur...

Add leading zeros
I am new to Sybase and fairly new to sql. I have a situation where I have to convert numbers in a column to a predifined character length. The numbers I have range from 1 character to 5 characters. They all need to be 7 characters with leading zeros and 01 at the end. Example: I have 323, it will need to be 0032301. Is this possible with sqlanywhere? Thanks, On 24 Apr 2007 17:08:22 -0700, Wayne Darby wrote: >I have 323, it will need to be 0032301 STRING() is one of the most valuable functions in SQL Anywhere, it's worth a bit of study. And LEFT() and RIGHT() are very h...

Leading Zeros in GridView
I have a number coming out of a database  (between 1 and around 900), but it needs to have leading zeros up to four digits (1 becomes 0001, 900 becomes 0900).I found an answer to another question that would add the leading zeros by transforming the string, but as I am adding this into a gridview using the 'Bind' argument (well so far), I can't use the solution. <ItemTemplate>       <asp:Label ID="Label_1" runat="server" Text='<%#Bind("Value")%>'></asp:Label> </ItemTemplate>...

csv and leading zeroes
I'm trying to write the contents of a csv file to a table, but I am having problems with fields with leading zeroes.  Whenever I save as csv I lose the leading zeroes.  Does anybody know how to prevent this? I don't know what data type you are using but you can use Decimal and Numeric so you can set precision and scale.  Try the link below for details.  Hope this helps.http://msdn2.microsoft.com/en-us/library/ms187746.aspxKind regards,Gift Peddie...

Leading zeros in SQL
I would like to add leading zeros in the date. Thsi is my existing procedure, it adds leading zeros, but it formats using "yyyy/mm/dd", instead of "yyyy-mm-dd" Select Id, Title, CONVERT(VARCHAR(10), ModifiedON, 111) --CAST(YEAR(ModifiedOn) AS VARCHAR(4))+'-'+CAST(MONTH(ModifiedOn) AS VARCHAR(2))+'-'+CAST(DAY(ModifiedOn) AS VARCHAR(2))as ModifiedOn From ActiveAds Where Row between @startRowIndex And @endRowIndexRafal Zikbay.com - Free Classifieds (Search Over 5 mln jobs on Zikbay.com) DNN Direct could just use "replace", not sure about ...

Web resources about - Leading zeroes - perl.beginners

Leading - Wikipedia, the free encyclopedia
... here. For the city and metropolitan borough in West Yorkshire, England, see Leeds . For other uses, see Lead (disambiguation) . "Line leading" ...

Buckeye Nation? Ohio State Dominates Oregon in Facebook Conversation Leading Up to Title Game
While the University of Oregon is favored over Ohio State University in Monday night’s College Football Playoff National Championship Game Presented ...

Hürriyet Daily News - LEADING NEWS SOURCE FOR TURKEY AND THE REGION
Hurriyet Daily News is the leading news source for Turkey and the region. Hurriyet daily news, turkish daily news, turkish news, hürriyet daily ...

Is Developer Forum Activity a Leading Indicator of Facebook Platform Economy Health?
Facebook developer Jesse Farmer has slurped the Developer Forums for the last 3 months and found some powerful trends: since January, posts per ...

Tehran Times - Iran's Leading International Daily
Tehran Times - Iran's Leading International Daily

CNN Leading Women (@CNNIwomen) on Twitter
Log in Sign up You are on Twitter Mobile because you are using an old version of Internet Explorer. Learn more here CNN Leading Women @ CNNIwomen ...

Virtual-Strategy Magazine - Your leading source for virtualization news
Virtual Strategy Magazine is an online publication devoted entirely to virtualization technologies.

Daily Times - Leading News Resource of Pakistan
DailyTimes delivers the latest breaking news and information on the latest top stories, entertainment, business, cricket, politics, and more. ...

Mobile News Online - The UK's leading mobile communication industry news site
This month, thousands of students will be starting university for the first time. Some will need new phones. Mystery Caller is on the case to ...

Who are the UK’s Leading Social Business Influencers?
We have attempted to create a list of the top Social Business Influencers in and around the UK. These influencers have, through what they have ...

Resources last updated: 1/16/2016 5:41:24 AM