ListToArray save my time
May 31
Currently, I'm on HL7 module for my current project. For HL7 project, we need to collect all of patient information and save it into text file. After that, we need to send this text file to another party. So we need to send all patient data by creating list value and separated by "|" as delimiters.
Here is example of MSH segment information.
For this case, we don't know how to check whether all of sequences are correct or not. If we check manually, it will take so long and not efficient for our testers and system analyst. That's why I need to write simple Coldfusion program for that. That's why I wrote the following coding.
2
3<cfloop index="i" list="#MyList#" delimiters="|">
4 <cfoutput>#i#</cfoutput><br>
5</cfloop>
When I render above coding, it output awful result and cannot fulfill what I want. Because, it cannot output sequence number and skipped empty sequence as follow.
2HISSAH
3HISSAH
4PCS
5201106011138
6ADT^A36
7AHIS00000004
8P
92.3
10AL
11NE
Fortunately, @seancorfield pointed me about to use ListToArray instead of ListGetAt here. That's why I don't need to write that much about what I want with ListToArray function. It's kinda useful and save my time. So, I've wrote as following.
2<cfset arr1 = listToArray (MyList, "|", false, true)>
3<cfdump var="#arr1#">
And result is as follow. It seems 95% work but skipped empty sequence.

So, I've read the documentation of ListToArray carefully and found that set as "false" if you don't want to skip empty value. That's why I've changed as follow and render it again.
2<cfset arr = listToArray (MyList, "|", true, true)>
3<cfdump var="#arr#">

It works 100% and got what I want. Thanks, God. It can save my time really.

Android
Top of Page
#1 by Larry C. Lyons on 6/3/11 - 1:12 PM
<cfset Foo = "Tom_delim_Dick_delim_Harry" />
<cfset Bar = foo.split("_delim_") />
This creates an array -very useful when you have multiple character delimiters.
#2 by ppshein on 6/3/11 - 10:38 PM