471,571 Members | 1,040 Online

# trim and REReplace

Hi,

I have this number: 00000000010000000099B I need to remove the 0s before 10 and 99 and the alphabets like B after 99. I also need to replace the 0s between 10 and 99 by "-". I don't know how to use trim and Rereplace for these two numbers in this string. Any Idea? I appreciate it. Thanks
Feb 28 '08 #1

An easy way would be to use two rereplaces, one for the first and one for the second number, e.g.
Expand|Select|Wrap|Line Numbers
1. <cfset startRange = REReplace(left(StreetNumber,10),"0+","")>
2. <cfset endRange = REReplace(right(StreetNumber,11),"^0+([1-9][0-9]+)[OEB]","\1")>
3. <cfset StreetNumber = startRange & endRange>

13 7557
acoder
16,027 Expert Mod 8TB
What's the pattern of these strings?

Replacing 0 and B is easy, but the 10 would make it more difficult because it has a 0!
Feb 28 '08 #2
Agree. I have this problem too. The pattern is : 10 digits at the beginning of the string (for the 1st number) + 10 more digits after (for the 2ed number) + 1 alphabet.

I think we should clean the 4 or 5 first digits (0s) from the beginning of the string then leave the next 5 digits then insert our "-" and again clean the 4 or 5 next 0s and leave the rest and again clean the alphabet. What do you think?
Feb 28 '08 #3
acoder
16,027 Expert Mod 8TB
That does make the problem easier because you have a consistent pattern.

However, I notice that in the example string you have 9 0s then 10. Is that correct or should it be 8 0s then a 10?
Feb 28 '08 #4
In this example I have 9 0s. but remember the 1st 10 digits are belong to 1st number. In this case number is 1 so we have 9 0s left. The real number could be 111 then we will have 7 0s before the number.
Feb 28 '08 #5
acoder
16,027 Expert Mod 8TB
Use something like ^0+([1-9]+)(0+)([1-9]+)([A-Z]?)\$ and replace with \$1-\$3.

I haven't tested this with REReplace, but it should give you an idea. It matches 0s at the beginning followed by a number followed by 0s followed by a number followed by letters.
Feb 28 '08 #6
Cool. I'll try it and let you know.
Feb 28 '08 #7
Here is the code:
<cfset StreetNumber = REReplace(#StreetNumber#,"^0+([1-9]+)(0+)([1-9]+)([A-Z]?)\$","\$1-\$3", "all")>

it will replace the whole StreetNumber by \$1-\$3. I tried it with trim() as well. It does the same. #StreetNumber# is 00000000010000000099B
Feb 28 '08 #8
I Got the exact pattern:

Street number ranges for near matches are returned in the following fixed-width format:

START RANGE (10 bytes) + END RANGE (10 bytes) + OEB code (1 byte) left-padded with zeros

Secondary (apartment) ranges for near matches are returned in the following fixed-width format:

START RANGE (8 bytes) + END RANGE (8 bytes) + OEB code (1 byte) left-padded with zeros

The OEB is “odd-even-both” code, meaning that the range either contains all Odd numbers, Even numbers, or Both.

In our example,

"00000000010000000099B" means “buildings 1-99 Both odd and even”, i.e. {1,2,3,4,…. 98,99}

As you see, all we need to do is chop off all leading zeros in each of the range blocks.

Please don't give up on me:-)
Feb 28 '08 #9
acoder
16,027 Expert Mod 8TB
Sorry, \$1-\$3 was JavaScript (and possibly other languages) notation for back-referencing. In Coldfusion, it's "\1-\3".
Feb 28 '08 #10
Thanks. But this replacement works only for this example. Did you get the chance to see the exact pattern I've posted? I need the "-" be in the middle of the numbers after cleaning. ^0+ works for START RANGE (10 bytes) But not for the END RANGE (10 bytes) because it will remove the 0s even if the start number is 10 or 100.
Feb 28 '08 #11
acoder
16,027 Expert Mod 8TB
An easy way would be to use two rereplaces, one for the first and one for the second number, e.g.
Expand|Select|Wrap|Line Numbers
1. <cfset startRange = REReplace(left(StreetNumber,10),"0+","")>
2. <cfset endRange = REReplace(right(StreetNumber,11),"^0+([1-9][0-9]+)[OEB]","\1")>
3. <cfset StreetNumber = startRange & endRange>
Feb 29 '08 #12
You’re awesome!!!!!
It's done exactly the way I wanted. Thank you sooooooo much for giving me your time. I really appreciate it.
Feb 29 '08 #13
acoder
16,027 Expert Mod 8TB
No problem, you're welcome as always.
Feb 29 '08 #14