Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.postscript > #795

Re: Simple string padding function in Postscript

Path csiph.com!usenet.pasdenom.info!weretis.net!feeder4.news.weretis.net!npeer.de.kpn-eurorings.net!npeer-ng0.de.kpn-eurorings.net!fu-berlin.de!uni-berlin.de!individual.net!not-for-mail
From Helge Blischke <h.blischke@acm.org>
Newsgroups comp.lang.postscript
Subject Re: Simple string padding function in Postscript
Followup-To comp.lang.postscript
Date Fri, 13 Jul 2012 21:19:24 +0200
Lines 26
Message-ID <a6baluF1v5U1@mid.individual.net> (permalink)
References <362f3578-16b0-4f21-994f-89412506d3b9@googlegroups.com>
Mime-Version 1.0
Content-Type text/plain; charset="us-ascii"
Content-Transfer-Encoding 7Bit
X-Trace individual.net 7AYF8PyrfMVOlev0NlH0RQ7gmpqFyDAUhkpPFRTZBN0/WOSVhhG5wOenm9r3tsMmDd
Cancel-Lock sha1:F1PQ1VuQBWMrBiFS6zUHUAoDCTk=
User-Agent KNode/0.99.01
Xref csiph.com comp.lang.postscript:795

Followups directed to: comp.lang.postscript

Show key headers only | View raw


Daniel Taylor wrote:

> I want to write a simple function to convert and integer into a string 6
> characters in length, padding with zeros as necessary. The function add
> the necessary zeros to the front of the string to make the overall length
> 6. Ideally I could pass the function the integer, and the length I want
> the string to be.
> 
> For example, if I input '1' I want the function to return '000001'
> 
> or if input '123' I want the function to return '000123'.
> 
> I've only recently started learning Postscript programming and this is one
> application I haven't been able to solve.

A fairly simple solution (without algorithmic arithmetic) is by the 
following procedure:

/bindec         % <integer> bindec <string_of_length_6>
{
        1000000 add 7 string cvs 1 6 getinterval
}bind def


Helge

Back to comp.lang.postscript | Previous | NextPrevious in thread | Next in thread | Find similar | Unroll thread


Thread

Simple string padding function in Postscript Daniel Taylor <daniel.taylor@nzpost.co.nz> - 2012-07-13 04:03 -0700
  Re: Simple string padding function in Postscript tlvp <mPiOsUcB.EtLlLvEp@att.net> - 2012-07-13 14:42 -0400
  Re: Simple string padding function in Postscript Helge Blischke <h.blischke@acm.org> - 2012-07-13 21:19 +0200
    Re: Simple string padding function in Postscript Daniel Taylor <daniel.taylor@nzpost.co.nz> - 2012-07-13 14:37 -0700
    Re: Simple string padding function in Postscript tlvp <mPiOsUcB.EtLlLvEp@att.net> - 2012-07-13 23:20 -0400

csiph-web