Ask a Question related to Coldfusion - Advanced Techniques, Design and Development.
-
Purple Haze #1
Need to Parse one value from two lines of data
Hi,
I'm doing a cfhttp request to a shipping rate provider and the response I get
back looks like this:
GND, NAS, SDS, EXP
$6.50, $12.25, $7.85, $14.00
The problem is that I only need to display to my end user the first bit of
data on the second line.
I thought I would be ok by parsing out the response and setting my delimiter
to a comma, but unfortunately the end of the first line doesn't end with a
comma so my code considers "EXP
$6.50" to be the value at position 4.
Anyone have any ideas on how I can just pull out the $6.50?
<cfhttp method="post" url="http://www.weburl.com">
<CFOUTPUT>
<cfhttpparam name="fromZip" type="formfield" value="#Zip_VendorInfo#">
<cfhttpparam name="toZip" type="formfield"
value="#GetShippingInformation.OrderShippingZip#">
<cfhttpparam name="weight" type="formfield"
value="#NumberFormat("#ShippingWeight#")#">
<cfhttpparam name="acctNum" type="formfield" value="#AccountNumber#">
</cfoutput>
</cfhttp>
<!--- here's the value being sent back from the server --->
<cfset api_response=cfhttp.fileContent>
<cfif isdefined("api_response")>
<!--- This is where we parse out all the necessary responses --->
<CFLOOP INDEX="ListElement" LIST="#api_response#" DELIMITERS=","></CFLOOP>
<cfset numberDelims = ListLen(api_response, ",")>
<cfset MyList = api_response>
<cfset MyArray = ListToArray(MyList, ",")>
<cfloop index="Element" from="4" to="5">
<cfoutput>
<cfswitch expression="#Element#">
<cfcase value="4"><cfset GNDRate = #MyArray[Element]#></cfcase>
</cfswitch>
</cfoutput>
</cfloop>
Resp: <cfoutput>#GNDRate#</cfoutput>
</CFIF>
Purple Haze Guest
-
How do I parse a txt File and write data into aDatabase
I'm trying to do an insert off of your example. It keeps throwing an error that it doesn't understand "fields1." Can you tell me where I might be... -
Data File, turn fields on mulitple lines into records on one li ne.. .
Please bottom post... John just provided a good one. Optionally if all you care about is determining whether a line contains a string it might... -
Using perl to parse specific lines by date...
While I've already done this with a simple shell script using grep, I was trying to figure out how I can do the same thing in perl. I have an... -
Is it possible to parse specific data from within large notes field?
I have a large DB with a text field that may have a fax number somewhere in it. I want to be able to extract into a separate field, the first 15... -
Can you parse data by an undefined pattern ?
Hi JS if there is consistency within the inconsistency then; I usually attack this kind of situation on a progressive yield hope and write a... -
jdeline #2
Re: Need to Parse one value from two lines of data
Consider treating the reply as a $-delimited list. Your second list element would be 6.50,
<CFSET temp = ListGetAt(api_response, 2, "$")>
<CFSET price = Mid(temp, 1, Len(temp) - 1)>
jdeline Guest
-
Purple Haze #3
Re: Need to Parse one value from two lines of data
thanks that did the trick
Purple Haze Guest
-
_jt #4
Re: Need to Parse one value from two lines of data
If the result are returned as rows of comma-delimited lists, you should
parse them as such, using CR & LF as a row delimiter and a comma as the
column delimiter. This method is not dependant on the specific format of
the individual column values.
<cfset rowDelim = chr(10)&chr(13)>
<cfset row = ListGetAt(api_response, 2, rDelim)>
<cfset columns = ListToArray(row)>
<cfset GNDRate = columns[1]>
_jt Guest



Reply With Quote

