Copy link to clipboard
Copied
Good afternoon all. I am working on a process that pulls in lines from a file one at a time. Each string is basically a list of tilde delimited values. Some of these values can vary in length or be NULL. I need to remove a few of those tildes with NULL values between them. For instace, my string may look something like the line below. I need to remove all but one of the tildes in that group at the end.
I have worked with ListDeleteAt() and tried to hit particular position number but that didn't quite work the way I'd hoped. I also worked with RemoveChars() a bit but those tildes are a different spot in each line. I am currently using the following but there may be a string of NULLs before the group I need to remove:
<cfset row = replace(row,"~~~~~~~~~","~","ONE")>
Any help would be appreciated.
MEPMD01~2POOP519~03092019113800PM~6480081580~~~1224714818389~OK~E~KWH~~000015~48~03092019124500AM~00~0.3414~00~0.3396~00~0.1182~00~0.0552~00~0.069~00~0.0642~~~~~~~~~00~0.0606~00~0.081
REreplace() will do it.
<cfset thisStr = REreplace(thisStr,"~+","~","all") />
HTH,
^ _ ^
UPDATE: I'll explain. It's a regular expression replace. ~+ means "one or more tilde"; when it finds a tilde, it replaces it with a tilde; if it finds several tilde, it replaces them all with a tilde. "all" scope means the entire string.
UPDATE2: If you are concerned about efficiency, you can have it replace _ONLY_ when two or more are consecutive.
<cfset thisStr = REreplace(thisStr,"~{2,}","~","all")
...
Copy link to clipboard
Copied
REreplace() will do it.
<cfset thisStr = REreplace(thisStr,"~+","~","all") />
HTH,
^ _ ^
UPDATE: I'll explain. It's a regular expression replace. ~+ means "one or more tilde"; when it finds a tilde, it replaces it with a tilde; if it finds several tilde, it replaces them all with a tilde. "all" scope means the entire string.
UPDATE2: If you are concerned about efficiency, you can have it replace _ONLY_ when two or more are consecutive.
<cfset thisStr = REreplace(thisStr,"~{2,}","~","all") />
{2,} means "two or more".
Copy link to clipboard
Copied
Thank you so much for that. I looked at the REreplace() function but wasn't sure of the syntax that would work. I'll see what I can do with this. This puts me on a great path. Thanks again.
Copy link to clipboard
Copied
You're welcome. Glad to help. And if what I offered turns out to be the correct answer, please mark my response as such, so that it can help others who might face the same issue. If not, then let me know and I'll help as best I can.
If you are not familiar with Regular Expressions, they are definitely worth learning. I know only a fraction of what they can do, but even that small amount has paid off in buckets.
V/r,
^ _ ^
Copy link to clipboard
Copied
Absolutely. Below is the syntax I wound up using and this works perfectly. Thank you again so much. Have a great weekend.
<cfset row = ReReplace(row,"~{4,}","~","ONE")>
Copy link to clipboard
Copied
Thank you for marking my answer as correct. Have a great weekend.
V/r,
^ _ ^