Skip to main content
Participant
April 6, 2009
Question

Trying to extract substring into a variable

  • April 6, 2009
  • 1 reply
  • 1005 views

I wanted to post to CFML General Discussion, but it is greyed out! Havent' seen these new Adobe forums - what a total convoluted mess! Horrible.

So, I have to post in this forum..

I just want to extract a substring from a line of text, and I can't find anywhere a straightforward way of doing this.

In a string, I can get the beginning column number and the length (to get to the end column), but I can't see how to put those columns (substring) into a new variable..

If I have this line (I put this string into variable called nws:

<area href="javascript:return(0)" alt="Forecast crest: 28.7 ft at 2:00am Apr 07">

I want to put this into a variable:
28.7 ft at 2:00am Apr 07

<cfset linelen = len(nws) - 2>
<cfset colb=find ("crest: ",nws) +7>
<cfset stringlen = linelen - colb>

Now I need something like:
<cfset crest = Substring of NWS starting in colb and going stringlen characters...

Thanks for any help

Howard Perlman
hperlman@usgs.gov
This topic has been closed for replies.

1 reply

Participant
April 6, 2009

Oops, never mind.

I found the MID function:

    <cfif find("Forecast crest",#nws#) is not "0">
        <cfset linelen = len(nws) - 2>
        <cfset colb=find ("crest: ",nws) +7>
        <cfset stringlen = linelen - colb + 1>
        <cfset crest = mid(nws,colb,stringlen)>
    </cfif>