Padding strings with zeros

here's a way to pad to 32 bits:

sub _pad32 { substr("0" x 32 . shift, -32); }

which is used in Image::Size in the following manner:

# _bin2int - converts binary string to decimal
sub _bin2int {unpack("N",pack("B32",substr("0"x32.shift,-32)));}

>>>Schoeneman, Carl 09/26/01 08:40pm >>>

Is there a way to pad a number with leading zeros with 1 command rather than 
the 2 I used below?  It looks like you're supposed to be able to zero-fill 
with sprintf but I couldn't figure it out.


_________________________________________________________________
Get your FREE download of MSN Explorer at http://explorer.msn.com/intl.asp

0
nwetters
9/27/2001 8:23:51 AM
perl.beginners 29388 articles. 4 followers. Follow

1 Replies
652 Views

Similar Articles

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

------_=_NextPart_001_01C14766.4A4CADA0
Content-Type: text/plain;
	charset="iso-8859-1"

	By adding a leading zero to the sprintf/printf processing:
		printf "%06s" will use up to 6 characters and pad with zeros.  

Wags ;)

-----Original Message-----
From: Nigel Wetters [mailto:nwetters@hotmail.com]
Sent: Thursday, September 27, 2001 01:24
To: beginners@perl.org; cschoeneman@microgeneral.com
Subject: Padding strings with zeros


here's a way to pad to 32 bits:

sub _pad32 { substr("0" x 32 . shift, -32); }

which is used in Image::Size in the following manner:

# _bin2int - converts binary string to decimal
sub _bin2int {unpack("N",pack("B32",substr("0"x32.shift,-32)));}

>>>Schoeneman, Carl 09/26/01 08:40pm >>>

Is there a way to pad a number with leading zeros with 1 command rather than 
the 2 I used below?  It looks like you're supposed to be able to zero-fill 
with sprintf but I couldn't figure it out.


_________________________________________________________________
Get your FREE download of MSN Explorer at http://explorer.msn.com/intl.asp


-- 
To unsubscribe, e-mail: beginners-unsubscribe@perl.org
For additional commands, e-mail: beginners-help@perl.org

------_=_NextPart_001_01C14766.4A4CADA0--
0
Wagner
9/27/2001 3:08:40 PM
Reply:

Similar Artilces:

How to pad string with leading zeroes
*** please ignore the post entitled 'Brian'. Its a duplicate of *** this post without a matching title Hi, I have a requirement to convert a 3-digit integer to a 3 character string padded with leading zeroes as I SELECT it from the database. Examples: ========= 1 converts to '001' 21 converts to '021' 321 converts to '321' I have played with several string functions to no avail. Any help/suggestions would be appreciated. Brian Two possible ways to get you going: select substring(convert(char(4),column + 1000),2,3) OR ...

string to string[]
Hi, I've got this code : string[] Params; string SQL = "SELECT * FROM T_MANAGEMENT_PAGES"; SqlCommand myCommand = new SqlCommand(SQL, myConnection); myConnection.Open(); SqlDataReader myReader = myCommand.ExecuteReader(); try { while (myReader.Read()) { Params_Type = myReader.GetValue(0).ToString(); } } catch { } finally { } myReader.Close(); My problem is to obtain Params_Type. But each time, it says : "impossible to convert '[object]' in 'string[]' &quo...

string() = string()
this code does not work (not instance of object) Dim Items(), Other() As String Items = New String() {"A","B","C"} Other = New String() {} Other = Items how can I get all the values ? angiras Hi, If I understand your requirement correctly, this should do it Dim Items() As String = {"A", "B", "C"} Dim Other(Items.Length - 1) As String Items.CopyTo(Other, 0) To more closely match you code above, but this will be less efficient Dim Items(), Other() As String ...

string padding
We=92re using PowerBuilder 10 (build 8011) and connecting to Microsoft SQL Server 2000 via ODBC. To prevent VARCHAR fields from being padded with spaces, we added the following lines to our pbodb100.ini file: PBTrimCatCharColumns=3d'YES' PBUseProcOwner=3d'YES' This works fine with DataWindows and embedded SQL, but VARCHAR values returned by reference as input/output parameters to stored procedures called via RPC are still being padded with spaces or truncated to match the length of the input parameter. For example, if we have a stored procedure foo, c...

Zero Padding
I have a value (stored in a local variable) that I want to zero-pad to keep the length (number of chars) the same. Is there some easy way to do this? I was looking at XPATH and it seems like there are some formatting functions that could possible do this. Does anyone have a good example of how to do this? Thanks. Matt, Using IDM 3.5 I would add an ECMAScript function like the one shown at the foot of this posting to my Driver and then if I wanted to pad with zeros on the left to a length of 13 I would invoke it in a Policy similar to this: <do-set-local-variable na...

String and String[]
What will be the advantage of using myString: String[10] over myString: String Man wrote: > What will be the advantage of using > myString: String[10] > over > myString: String "String[10]" is a fixed-length, statically allocated, Ansi-based ShortString. "String" is a dynamic-length, dynamically allocated, reference counted, Ansi-based or Unicode-based (depening on Delphi version) Long string. Unless you absolutely need the static, fixed length nature of ShortString, such as in records that interact with external systems, you should stay ...

String Padding
I'm using PB 6.5 with MSSQL 7 connecting through ODBC. When I select a "character" column from a table it returns the value padded with white space at the end. Is there a way to prevent this? I didn't encounter this problem when using ASA6 database. Thanks, James Knowlton Look in MS Sql Books on line about ANSI Padding. For ODBC add "PBTrimCharColumns='YES'" to pbodb70.ini in the MS SQLServer section. The alternative is to use MSS driver, it uses MS db_lib calls that automatically remove trailing spaces "James Knowlton&quo...

string and string[]
hello, whats the difference here between string and string[] thanks "string" denotes an item of type String "string[]" denotes an array of type String itemsThanks, EdMicrosoft MVP - ASP/ASP.NET Gracia mon ami...

String and string?
Hi guys, I was wondering the difference between small letter string type and a capital letter String type. Does anyone know about this? Highly appreciate for your answers! Thankz! The "proper" version is String, as it references the System.String class of the .NET Framework Class Library. The ability to use string is provided by C#, where it is an alias to String. Similarly, the "proper" version of an integer is Int32, as it references System.Int32.  The ability to use int is provided by C#, and the ability to use Integer is provided by VB.NET, and both int and Integer are aliases...

Zero-width split() match creates empty trailing strings but not empty leading strings
The perlfunc documentation spells this out clearly, and it matches what I see: $ perl -e 'for (split(//, "fob", -1)) { print "$_\n"; }' | sed -e 's/^$/<blank>/' f o b <blank> The question on my mind is why. In particular, is it a decision worth replicating to language's libraries? Thanks for any pointers. I tried to find the source for split, and I think I may have found it in pp_split in pp.c. But there's not really any reason to expect the source code to include the justification, and I couldn't find one. http:/...

a string in a string in a string in my code behind....
I know my title talk about code-behind, but this is really a client-side problem (and surely a newby one too, sorry about that).I have a javascript function that my make a little text appear when the onmouseover event of a link is activated.So, normally, if my link was inside my html code, it would be something like this:<a href = "whocare.com"  onmouseover="poplink('I want to test something');">test</a>BUT, for some reason, I have to write this part in code behind with the LiteralControl function....and that will give something like that:this.Controls.Add(new LiteralCo...

superreview granted: [Bug 277479] Make atoms hold PRUnichar strings again : [Attachment 172366] zero-copy atom lookup from UTF16 strings (for existing atoms)
Boris Zbarsky <bzbarsky@mit.edu> has granted Boris Zbarsky <bzbarsky@mit.edu>'s request for superreview: Bug 277479: Make atoms hold PRUnichar strings again https://bugzilla.mozilla.org/show_bug.cgi?id=277479 Attachment 172366: zero-copy atom lookup from UTF16 strings (for existing atoms) https://bugzilla.mozilla.org/attachment.cgi?id=172366&action=edit ------- Additional Comments from Boris Zbarsky <bzbarsky@mit.edu> >Index: xpcom/ds/nsAtomTable.cpp >+// An AtomTableEntry can be either a string key to be used with the >+// atom table, or an a...

superreview requested: [Bug 277479] Make atoms hold PRUnichar strings again : [Attachment 172366] zero-copy atom lookup from UTF16 strings (for existing atoms)
Boris Zbarsky <bzbarsky@mit.edu> has asked Boris Zbarsky <bzbarsky@mit.edu> for superreview: Bug 277479: Make atoms hold PRUnichar strings again https://bugzilla.mozilla.org/show_bug.cgi?id=277479 Attachment 172366: zero-copy atom lookup from UTF16 strings (for existing atoms) https://bugzilla.mozilla.org/attachment.cgi?id=172366&action=edit ------- Additional Comments from Boris Zbarsky <bzbarsky@mit.edu> Benjamin, you want to review? ...

m_AVP As IDictionary(Of String, String) = New Dictionary(Of String, String) ,not defined?
   I am creating a usercontrol (ascx,ascx.vb)   I have used Imports system.Collections Imports system.Collections.Generic     Private m_AttributeValuePair As IDictionary(Of String, String) = New Dictionary(Of String, String)     But I am gettting an error “Type Dictionary is not defined”   And also I am getting intelisense to type the line But what is the reason for my error ? How can I get escape from the error ?         this error is not showing today  ...

Web resources about - Padding strings with zeros - perl.beginners

Optimal asymmetric encryption padding - Wikipedia, the free encyclopedia
and subsequently standardized in PKCS#1 v2 and RFC 2437 . The OAEP algorithm is a form of Feistel network which uses a pair of random oracles ...

Clintonworld is centre of pocket padding universe
Clinton nostalgia is being replaced by Clinton neuralgia.

MP sorry for padding his resume
State Liberal MP David Southwick apologises for misleading personal information on his website.

Former treasurer Peter Costello warns tax reform hard without 'padding' in public opinion, more difficult ...
Peter Costello warns the Government tax reform will be difficult and that it may not have the political capital to pull it off.

Padding and the Contractor
If padding hours is a problem in Biglaw, imagine what would happen if you paid lawyers by the hour.

Contractor Accuses LA Times of Padding Circulation Figures
In 2007, the U.S. Attorney’s office in Brooklyn announced it was ceasing prosecution of Tribune publications Newsday and Hoy for padding circulation ...

That's Not Padding, My Resume's Just Fat
That's Not Padding, My Resume's Just Fat

Recalls: 2013 Ford C-Max Hybrid recalled over lack of roof padding
Filed under: Hybrid , Minivan/Van , Wagon , Recalls , Safety , Ford Ford is recalling 33,021 units of its 2013 C-Max Hybrid not equipped with ...

The truth behind padding your CV
When looking for a job, every little bit counts — as long as it’s true.

Rams, Edward Jones Dome Cover Concrete with Padding After Reggie Bush's Injury - Bleacher Report
On the heels of injuries suffered by San Francisco 49ers running back Reggie Bush and Cleveland Browns quarterback Josh McCown at the Edward ...

Resources last updated: 12/18/2015 11:15:38 AM