473,398 Members | 2,088 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,398 software developers and data experts.

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

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
==========================================


Jul 19 '05 #1
5 2577
bart plessers wrote:
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)
Jul 19 '05 #2
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

"bart plessers" <ba**********@hotmail.com> wrote in message
news:OE**************@TK2MSFTNGP10.phx.gbl...
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
==========================================


Jul 19 '05 #3
"Bob Barrows" <re*******@yahoo.com> wrote in message
news:uu*************@tk2msftngp13.phx.gbl...
bart plessers wrote:
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)


newstring = Right("0000000" & i,8)

;-p
Jul 19 '05 #4
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
--
Will trade ASP help for SQL Server help
"Chris Hohmann" <hohmannATyahooDOTcom> wrote in message
news:OA**************@TK2MSFTNGP10.phx.gbl...
"Bob Barrows" <re*******@yahoo.com> wrote in message
news:uu*************@tk2msftngp13.phx.gbl...
bart plessers wrote:
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)


newstring = Right("0000000" & i,8)

;-p

Jul 19 '05 #5
"Ray at <%=sLocation%>" <myfirstname at lane34 dot com> wrote in message
news:Oh**************@tk2msftngp13.phx.gbl...
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
Jul 19 '05 #6

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

9
by: John F Dutcher | last post by:
I use code like the following to retrieve fields from a form: recd = recd.append(string.ljust(form.getfirst("lname",' '),15)) recd.append(string.ljust(form.getfirst("fname",' '),15)) etc.,...
14
by: Spare Change | last post by:
I am told that I can have a dynamic or static string array. So if I declare string dynamic; How do I add elements to dynamic and resize it ?
3
by: Mathieu Malaterre | last post by:
Hello, I guess this might be a very dummy question, but I couldn't find an answer in the group's archive. I am reading DICOM files, and to store the string read I use std::string....
4
by: Niyazi | last post by:
Hi I am trying to insert some value into SQL Server 2000 tables and I am keep getting the "Input string was not in a correct format" error. When user fills the Form it updates the table call...
1
by: Andrew | last post by:
I run a fixed-width export based on a query, and the query looks like this... Clients.SSN, Clients.ClientID, ServiceEvents.SeviceDate, CStr(Format(,"0000")) AS Servs, "28" AS SETTING, FROM...
1
by: Magix | last post by:
Hi, I would like to replace title string into a file. My output file looks like this: Name Age Address ==== === ...
5
by: ywchan | last post by:
I would like to convert a string to a fixed length e.g. if fixed length = 10 'abc' -> ' abc' 'abcdefghijklm' -> 'abcdefghij' Is there any simple function in C# can perform this operation?...
8
by: cdolphin88 | last post by:
Hi, I'm reading from a .dat file and I want to know the length of the string . I' using the stringRef.length () but the compiler said there was an error `stringRef' undeclared (first use...
17
by: JRough | last post by:
I have used this function to create a string called $headers: function GetHeaders($file_name){ return "<th><a href='".$file_name."&order_by=l_e'>L_E</a></th> <th><a...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.