Trim leading zeros from string
Author |
Message |
Dirk Goldga #1 / 8
|
 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 |
|
 |
Glenn Robbin #2 / 8
|
 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 |
|
 |
Dirk Goldga #3 / 8
|
 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 |
|
 |
Dirk Goldga #4 / 8
|
 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 |
|
 |
Douglas J. Taylor Jr #5 / 8
|
 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 |
|
 |
Dirk Goldga #6 / 8
|
 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 |
|
 |
davi #7 / 8
|
 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 |
|
 |
Dirk Goldga #8 / 8
|
 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 |
|
|
|