Trim leading zeros from string 
Author Message
 Trim leading zeros from string

I'm looking for an *efficient* method of t{*filter*} leading zeros from a
string.  Yes, I'm aware that I can loop through the characters in the
string using Mid$(string, pos, 1) until I find a non-zero, and then
take Mid$(string, pos).  But that takes a long time, execution-wise,
compared to the instruction sequences I can use on the (gasp!)
mainframe.  Is there some quick way to trim leading zeros, or translate
them to spaces, or even just to find the first character that is *not*
a zero?

Thank you for your consideration.

--
Dirk Goldgar

(please direct email replies to

Sent via Deja.com http://www.*-*-*.com/
Share what you know. Learn what you don't.



Mon, 25 Feb 2002 03:00:00 GMT  
 Trim leading zeros from string
Dick:

Dim strNum as string, lngNum as string
strNum = "000012345"
lngNum = strNum
strNum = lngNum

Use a intger/single/double for the declaration of the number variable as
appropriate.
GR

Quote:

> I'm looking for an *efficient* method of t{*filter*} leading zeros from a
> string.  Yes, I'm aware that I can loop through the characters in the
> string using Mid$(string, pos, 1) until I find a non-zero, and then
> take Mid$(string, pos).  But that takes a long time, execution-wise,
> compared to the instruction sequences I can use on the (gasp!)
> mainframe.  Is there some quick way to trim leading zeros, or translate
> them to spaces, or even just to find the first character that is *not*
> a zero?

> Thank you for your consideration.

> --
> Dirk Goldgar

> (please direct email replies to

> Sent via Deja.com http://www.*-*-*.com/
> Share what you know. Learn what you don't.



Mon, 25 Feb 2002 03:00:00 GMT  
 Trim leading zeros from string
Thanks, Glenn.  So far, that's the best I've been able to come up with.  It
just seems there should be a faster, string-based way!  All I really need is
a (fast) function that locates the first character in one string that is not
in another -- a "For intPos = 1 to Length(strMystring)" loop just doesn't
cut it.

--

Quote:

>Dick:

>Dim strNum as string, lngNum as string
>strNum = "000012345"
>lngNum = strNum
>strNum = lngNum

>Use a intger/single/double for the declaration of the number variable as
>appropriate.
>GR


>> I'm looking for an *efficient* method of t{*filter*} leading zeros from a
>> string.  Yes, I'm aware that I can loop through the characters in the
>> string using Mid$(string, pos, 1) until I find a non-zero, and then
>> take Mid$(string, pos).  But that takes a long time, execution-wise,
>> compared to the instruction sequences I can use on the (gasp!)
>> mainframe.  Is there some quick way to trim leading zeros, or translate
>> them to spaces, or even just to find the first character that is *not*
>> a zero?

>> Thank you for your consideration.

>> --
>> Dirk Goldgar

>> (please direct email replies to

>> Sent via Deja.com http://www.*-*-*.com/
>> Share what you know. Learn what you don't.



Tue, 26 Feb 2002 03:00:00 GMT  
 Trim leading zeros from string
Incidentally, though the numbers I'm working are too big to use a Long for
the method Glenn Robbins proposed, either a Double or a Currency would do.
Of the two choices, Currency tests out as faster.

--

Dirk Goldgar
(to reply via email, remove NOSPAM from address)

Quote:

>Thanks, Glenn.  So far, that's the best I've been able to come up with.  It
>just seems there should be a faster, string-based way!  All I really need
is
>a (fast) function that locates the first character in one string that is
not
>in another -- a "For intPos = 1 to Length(strMystring)" loop just doesn't
>cut it.

>--


>>Dick:

>>Dim strNum as string, lngNum as string
>>strNum = "000012345"
>>lngNum = strNum
>>strNum = lngNum

>>Use a intger/single/double for the declaration of the number variable as
>>appropriate.
>>GR


>>> I'm looking for an *efficient* method of t{*filter*} leading zeros from a
>>> string.  Yes, I'm aware that I can loop through the characters in the
>>> string using Mid$(string, pos, 1) until I find a non-zero, and then
>>> take Mid$(string, pos).  But that takes a long time, execution-wise,
>>> compared to the instruction sequences I can use on the (gasp!)
>>> mainframe.  Is there some quick way to trim leading zeros, or translate
>>> them to spaces, or even just to find the first character that is *not*
>>> a zero?

>>> Thank you for your consideration.

>>> --
>>> Dirk Goldgar

>>> (please direct email replies to

>>> Sent via Deja.com http://www.*-*-*.com/
>>> Share what you know. Learn what you don't.



Tue, 26 Feb 2002 03:00:00 GMT  
 Trim leading zeros from string
Maybe not any faster but here's another way...

Dim strNum As String
strNum = "000012345"
strNum = Format(strNum)
Debug.Print strNum
--
Doug
Reply to is anti-spammed remove the "z" from email

Quote:

>Thanks, Glenn.  So far, that's the best I've been able to come up with.  It
>just seems there should be a faster, string-based way!  All I really need
is
>a (fast) function that locates the first character in one string that is
not
>in another -- a "For intPos = 1 to Length(strMystring)" loop just doesn't
>cut it.


>>Dick:

>>Dim strNum as string, lngNum as string
>>strNum = "000012345"
>>lngNum = strNum
>>strNum = lngNum

>>Use a intger/single/double for the declaration of the number variable as
>>appropriate.
>>GR

<Snip>


Tue, 26 Feb 2002 03:00:00 GMT  
 Trim leading zeros from string
Thanks, Doug, I'll time it on Monday & see how it stacks up.
--

Dirk Goldgar
(to reply via email, remove NOSPAM from address)


Quote:
>Maybe not any faster but here's another way...

>Dim strNum As String
>strNum = "000012345"
>strNum = Format(strNum)
>Debug.Print strNum
>--
>Doug



Wed, 27 Feb 2002 03:00:00 GMT  
 Trim leading zeros from string
    lngNum = CLng(strNum)
    strNum = CStr(lngNum)

explicit type conversions are always faster than implicit type conversions
(PS Str$ is faster than Str is faster than Format$ is faster than Format)

Of course at these speeds, who cares?

Quote:

>Dick:

>Dim strNum as string, lngNum as string
>strNum = "000012345"
>lngNum = strNum
>strNum = lngNum

>Use a intger/single/double for the declaration of the number variable as
>appropriate.
>GR


>> I'm looking for an *efficient* method of t{*filter*} leading zeros from a
>> string.  Yes, I'm aware that I can loop through the characters in the
>> string using Mid$(string, pos, 1) until I find a non-zero, and then
>> take Mid$(string, pos).  But that takes a long time, execution-wise,
>> compared to the instruction sequences I can use on the (gasp!)
>> mainframe.  Is there some quick way to trim leading zeros, or translate
>> them to spaces, or even just to find the first character that is *not*
>> a zero?

>> Thank you for your consideration.

>> --
>> Dirk Goldgar

>> (please direct email replies to

>> Sent via Deja.com http://www.*-*-*.com/
>> Share what you know. Learn what you don't.



Thu, 28 Feb 2002 03:00:00 GMT  
 Trim leading zeros from string
Thanks, Doug.  I've checked it out, and using Format() is slower than the
other methods proposed, although it may work when dealing with numbers
larger than the largest numeric format.  So far, the fastest method I've
found, for numbers bigger than Longs,  is converting to Currency and back.

--


Quote:
>Maybe not any faster but here's another way...

>Dim strNum As String
>strNum = "000012345"
>strNum = Format(strNum)
>Debug.Print strNum
>--
>Doug
>Reply to is anti-spammed remove the "z" from email


>>Thanks, Glenn.  So far, that's the best I've been able to come up with.
It
>>just seems there should be a faster, string-based way!  All I really need
>is
>>a (fast) function that locates the first character in one string that is
>not
>>in another -- a "For intPos = 1 to Length(strMystring)" loop just doesn't
>>cut it.


>>>Dick:

>>>Dim strNum as string, lngNum as string
>>>strNum = "000012345"
>>>lngNum = strNum
>>>strNum = lngNum

>>>Use a intger/single/double for the declaration of the number variable as
>>>appropriate.
>>>GR

><Snip>



Fri, 01 Mar 2002 03:00:00 GMT  
 
 [ 8 post ] 

 Relevant Pages 

1. Trimming Leading Zeros!!

2. VsFlexGrid Pro 7: Leading zeroes are suppressed when entering a string value

3. Most efficient way to strip leading zeros from string

4. treeview - leading spaces in text are trimmed

5. Leading Spaces Trimmed in Crystal Report Label Multi-Line Caption

6. Help TRIM left padded zeros...

7. leading zeros

8. Leading Zeros

9. Adding leading zeros ???

10. Leading zeros in minutes

11. Excel VBA - Pad SSN's w/Leading Zeros

12. Excel Xp VBA - Pad SSN's w/Leading Zero's

 

 
Powered by phpBB® Forum Software