Parsing of field

This is a discussion on Parsing of field within the Cold Fusion forums in Application Servers & Tools category; I am trying to parse a field, I cannot use right or left because the item isn't in the same place. Here is an example of the field data; 'MEISTER 56767 CB5-325-3-M-84-55 IGE 60DEG 6.5MMX14/M4.5 (G-213 MOD); FSP100:034250006500001; FSP200:RSRV-189' I need to get FSP100:034250006500001 from the field. Any ideas....

Go Back   Application Development Forum > Application Servers & Tools > Cold Fusion

Object Mix

Register FAQ Calendar Search Today's Posts Mark Forums Read
  #1  
Old 09-05-2008, 09:04 AM
rjproctor
Guest
 
Default Parsing of field

I am trying to parse a field, I cannot use right or left because the item isn't
in the same place. Here is an example of the field data;

'MEISTER 56767 CB5-325-3-M-84-55 IGE 60DEG 6.5MMX14/M4.5 (G-213 MOD);
FSP100:034250006500001; FSP200:RSRV-189'

I need to get FSP100:034250006500001 from the field.

Any ideas.

Reply With Quote
  #2  
Old 09-05-2008, 09:12 AM
Dan Bracuk
Guest
 
Default Re: Parsing of field

Your specific example is a list with semi-colons as the delimiter.
Reply With Quote
  #3  
Old 09-05-2008, 09:17 AM
rjproctor
Guest
 
Default Re: Parsing of field

Yes it is, so how do I parse the field to parse within cf to see the semi-colons
Reply With Quote
  #4  
Old 09-05-2008, 09:29 AM
Ian Skinner
Guest
 
Default Re: Parsing of field

rjproctor wrote:
> Yes it is, so how do I parse the field to parse within cf to see the semi-colons


If one where to read some of the ColdFusion documentation concerning
it's list functions, one would learn that all the list functions allows
one to specify the list delimiting charatcer(s) as a parameter of the
function.

I.E. <cfoutput>#listLen('MEISTER 56767 CB5-325-3-M-84-55 IGE 60DEG
6.5MMX14/M4.5 (G-213 MOD);FSP100:034250006500001; FSP200:RSRV-189',';')
Reply With Quote
  #5  
Old 09-05-2008, 10:23 AM
rjproctor
Guest
 
Default Re: Parsing of field

OK, the listlen will give me the no of semicolons, but there are multiple semicolons and the item that I need isn't always after the 3rd semicolon but it is always after the FSP100:
Reply With Quote
  #6  
Old 09-05-2008, 10:44 AM
Ian Skinner
Guest
 
Default Re: Parsing of field

rjproctor wrote:
> OK, the listlen will give me the no of semicolons, but there are multiple semicolons and the item that I need isn't always after the 3rd semicolon but it is always after the FSP100:


Then you are looking for a regular expression search using the ReFind()
function. A read of the documentation for ReFind() and how to use the
resulting structure maybe in order.

<cfdump var="#refind('FSP100.*?);','MEISTER 56767 CB5-325-3-M-84-55
IGE 60DEG 6.5MMX14/M4.5 (G-213 MOD); FSP100:034250006500001;
FSP200:RSRV-189',1,true)#">
Reply With Quote
  #7  
Old 09-05-2008, 10:45 AM
davidsimms
Guest
 
Default Re: Parsing of field

<cfset list = "MEISTER 56767 CB5-325-3-M-84-55 IGE 60DEG 6.5MMX14/M4.5 (G-213
MOD); FSP100:034250006500001; FSP200:RSRV-189">

<cfset posInList = "Not found">

<cfset counter = 0>
<cfloop list="#list#" index="i" delimiters=";">
<cfset counter = counter + 1>
<cfset i = trim(i)>
<cfif left(i, "7") EQ "FSP100:">
<cfset posInList = counter>
<cfbreak>
</cfif>
</cfloop>

<cfoutput>#posInList#</cfoutput>

Reply With Quote
  #8  
Old 09-05-2008, 11:07 AM
Dan Bracuk
Guest
 
Default Re: Parsing of field

[q]Originally posted by: rjproctor
OK, the listlen will give me the no of semicolons, but there are multiple
semicolons and the item that I need isn't always after the 3rd semicolon but it
is always after the FSP100:[/q]

This might be the simplest way:
Use find to get the postition of FSP100:
Use RemoveChars to make FSP100: the first characters of your string
Use ListFirst to get the final answer.

Usage of all 3 functions are in the cfml reference manual. If you don't have
one, the internet does.

Reply With Quote
  #9  
Old 09-06-2008, 03:00 AM
BKBK
Guest
 
Default Re: Parsing of field

Davidsimms has effectively wriiten the code for you. Oh, and don't double-post.


Reply With Quote
Reply


Thread Tools
Display Modes


All times are GMT -5. The time now is 03:16 PM.


Powered by vBulletin® Version 3.7.2
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.2.0
vB Ad Management by =RedTyger=

In an effort to better serve ads to our visitors, cookies are used on objectmix.com. For more information, check out our Privacy Policy.