string question: how to append x zeros to get fixed lenght string?

C

Chris Hohmann

Ray at said:
I'd put it in a function.

Function PadInt(iNum, iPadLength)
PadInt = Right(String(iPadLength, "0") & Cstr(iNum), iPadLength)
End Function

Response.write PadInt(34234, 8)

In my prior post I was making a (overly) subtle point about wasting 0's.
Back in my day, we didn't even have 1's and 0's. We have to use l's and
O's and only the executives got keyboards. The rest of us had to tap out
binary on the keyboard port.

Function PadInt(iNum, iPadLength)
PadInt = Right(String(iPadLength - 1, "0") & Cstr(iNum), iPadLength)
End Function

-Chr15
 
B

bart plessers

Hi,

I have a counter i
Now I want to derive a fixed lenght string from this counter :
1 -> "00000001"
52 -> "00000052"
12896 -> "00012896"

What is the fastest way to do this?
This is part of a recursive subroutine, so the command will be executed
quite a lot.

Any suggestions?

tia

bartp


--

==========================================
Hyper A.R.T.
bart plessers
Paul Van Ostaijenlaan 4
3001 Heverlee
BELGIUM
tel: +32 (16) 23.40.85
fax: +32 (16) 23.41.06
==========================================
 
B

Bob Barrows

bart said:
Hi,

I have a counter i
Now I want to derive a fixed lenght string from this counter :
1 -> "00000001"
52 -> "00000052"
12896 -> "00012896"

What is the fastest way to do this?
This is part of a recursive subroutine, so the command will be
executed quite a lot.

Any suggestions?

tia

bartp

newstring = right("000000000" & i,9)
 
J

jason kennedy

hmmmm

use len perhaps. you want 8 digits

my_len = len(my_counter)

my_len = 8 - my_len

for a = 1 to my_len
my_prefix = my_prefix & "0"
next

response.write my_prefix & my_counter

something like that would do it
i'm sure ray will have a one line solution, but he is heading for deity
status and i'm not

:p

jason
 
R

Ray at

I'd put it in a function.

Function PadInt(iNum, iPadLength)
PadInt = Right(String(iPadLength, "0") & Cstr(iNum), iPadLength)
End Function

Response.write PadInt(34234, 8)

:p

Ray at home
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,007
Latest member
obedient dusk

Latest Threads

Top