473,395 Members | 1,418 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,395 software developers and data experts.

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

✓ answered by acoder

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

Sign in to post your reply or Sign up for a free account.

Similar topics

22
by: Simon | last post by:
Hi, I have written a function to trim char *, but I have been told that my way could be dangerous and that I should use memmove(...) instead. but I am not sure why my code could be 'dangerous'...
5
by: Alex Vassiliev | last post by:
Hi all. Just wanted to share two handy RegEx expressions to strips leading and trailing white-space from a string, and to replace all repeated spaces, newlines and tabs with a single space. *...
12
by: Robert Mark Bram | last post by:
Hi All, I am using the following trim function: function trim (str) { return str.replace(/^\s*/g, '').replace(/\s*$/g, ''); } The problem is that this doesn't trim instances of the...
3
by: FlyerN87 | last post by:
For some reason this command will not trim the names shown in the fields listed. I'm trying to do this in a text box on a report. I've done this fairly succesfully in other reports but I must...
11
by: Darren Anderson | last post by:
I have a function that I've tried using in an if then statement and I've found that no matter how much reworking I do with the code, the expected result is incorrect. the code: If Not...
7
by: Sascha Herpers | last post by:
Hi, what is the difference between the trim function and the trim String-member? As far as I see it, both return the trimmed string and leave the original string unaltered. Is any of the two...
22
by: Terry Olsen | last post by:
I have an app that makes decisions based on string content. I need to make sure that a string does not contain only spaces or newlines. I am using the syntax 'Trim(String)" and it works fine. I...
1
by: arsaral | last post by:
Hi, Here is an extension of MSDN's trim right example to trim left-right... First subroutines then the calling structure is given below... Cheers. Ali Riza SARAL ...
31
by: rkk | last post by:
Hi, I've written a small trim function to trim away the whitespaces in a given string. It works well with solaris forte cc compiler, but on mingw/cygwin gcc it isn't. Here is the code: char...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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
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
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...

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.