Skip to main content
Participating Frequently
January 31, 2020
Answered

tilde delimited sting into a list

  • January 31, 2020
  • 1 reply
  • 1364 views

Good afternoon. My apologies for the flurry of questions. This may seem like a rerun but 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 change the value of certain items in that list. I have tried using ListSetAt() to try to do this. I use the syntax below against the line below that. This should be changing the value of position 13 in that string, which is currently 48 to a value of 9. Rather, it is changing the value of what is now 0.3414 in position 16. It appears that it is still not recognizing those NULL values between tildes despite having that "YES" argument at the end. Again, any help would be appreciated.

 

         <cfset row = ListSetAt(row,14,9,"~","YES")>

 

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

This topic has been closed for replies.
Correct answer WolfShade

Unless I'm missing something, the value of 48 is in the 13th position, not 14th, if I count correctly.

 

But aside from that, you'd probably have better luck by converting the list to an array (with including empty values) and changing the array by the index position, then convert back to a list.

 

HTH,

 

^ _ ^

1 reply

WolfShade
WolfShadeCorrect answer
Brainiac
January 31, 2020

Unless I'm missing something, the value of 48 is in the 13th position, not 14th, if I count correctly.

 

But aside from that, you'd probably have better luck by converting the list to an array (with including empty values) and changing the array by the index position, then convert back to a list.

 

HTH,

 

^ _ ^

PhamaldaAuthor
Participating Frequently
January 31, 2020

Oh yes sir. Sorry about that. I have made that change above. That should be position 13. 

PhamaldaAuthor
Participating Frequently
February 6, 2020

When I run the code 

 

<cfset row="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">
<cfset row = listSetAt(row,13,9,"~","yes")>
<cfoutput>#row#</cfoutput>

 

I get the output: MEPMD01~2POOP519~03092019113800PM~6480081580~~~1224714818389~OK~E~KWH~~000015~9~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

So, please mark WolfShade's suggestion as the correct answer.


My apologies for the delayed response sir. That is so weird. I swear that wasn't working last week. I am still working with the option of converting that string to an array and then back. I do think that will be the best option. I'll keep you posted on that and mark that as answered as soon as I have that worked out. Thank you again for your time and effort.