[thelist] [ColdFusion] parsing text

Scott Brady evolt at scottbrady.net
Thu Jul 1 16:33:14 CDT 2004


Original Message:
> From: "Kyle Murphy" 

> =============STAMP: 2004/06/23 14:54:45 MATTHEW  
> I just called and Confirmed Jane Smiling with Teresa on the 4th. 
>  
> =============STAMP: 2004/06/22 15:33:37 MATTHEW  
> Teresa had already filled the need that Denise just called in. 

> NoteDate			Note
> ----------------		---------
> 2004/06/23 14:54:45	I just called and Confirmed Jane Smiling with
> Teresa on the 4th.
> 2004/06/22 15:33:37	Teresa had already filled the need that Denise
> just called in.

Off the top of my head:

This is essentially a "list" with "==========STAMP:" as the delimiter [above, there are two elements to the list].  Since I don't think you can actually use that string as the delimiter in a CF list, I'd say replace that string with a single character you know won't be anywhere else in the text.  I'd probably use the "|", but that's not guaranteed to not be there.  Assuming you know that won't be in there, I'd first do a:

ReplaceNoCase(yourString,"=============STAMP:","|","ALL")

You can then loop over your test, treating as a list with | as the delimiter:

<cfloop list="#yourString#" delimiters="|" index="i">

Now, each element in that list is ALSO a list delimited by spaces.  The first two elements are the date, you ignore the 3rd element, and then rest of the elements starting with the 4th are the actual note.

So, to get those:

<cfset noteDate = ListGetAt(i,1," ") & " " ListGetAt(i,2," ")>
<!--- This one is trickier,basically, delete the first 3 elements --->
<cfset theNote = i>
<cfloop from="1" to="3" index="j">
     <cfset theNote = ListDeleteAt(theNote,1," ")>
</cfloop>

That gives you the individual notes.  Here's my code all in one block (no guarantee it works, as is, but it should):

NoteDate			Note<br />
----------------		---------<br />
<cfset yourString = ReplaceNoCase(yourString,"=============STAMP:","|","ALL")>
<cfloop list="#yourString#" delimiters="|" index="i">
     <cfset noteDate = ListGetAt(i,1," ") & " " ListGetAt(i,2," ")>
     <cfset theNote = i>
     <cfloop from="1" to="3" index="j">
          <cfset theNote = ListDeleteAt(theNote,1," ")>
     </cfloop>
<cfoutput>
#variables.noteDate#               #variables.theNote#<br />
</cfoutput>
</cfloop>

----------------------------
Scott Brady
http://www.scottbrady.net/




More information about the thelist mailing list