Jump to content

Wanted: cf to extract string between delimiters


This topic is 5796 days old. Please don't post here. Open a new topic instead.

Recommended Posts

I've looked and I can't find so please forgive if this has already been solved

I want to extract the url containing the word (or part of word) contact from a list of urls.

Here is an example of the raw list:

[23] http://192.168.0.200/FEEDBACK.HTM[24] http://192.168.0.200/ADVERTISE.HTM[25] http://192.168.0.200/CONTACTS.HTM[26]

I would like to have his returned:

http://192.168.0.200/CONTACTS.HTM

Any ideas would be appreciated (I've bashed my head against this for hours)

Cheers

Pete

Link to comment
Share on other sites

It looks like you need a little creative use of the script step: Position ( text ; searchString ; start ; occurrence ).

e.g. You could run a loop that finds words beginning with "http:" and loads them into a repeating field, then you would have all the addresses in the repeating field and it would leave out any other extraneous rubbish.

If the addresses come with the "[XX]" tacked on the end, you might also want to remove this as a step in the loop too.

Anatole

Link to comment
Share on other sites

It doesn't seem too difficult, but some points require clarification:

extract the url containing the word (or part of word) contact

1. What does "part of word" mean? Do words like "control" or "intact" contain part of the word "contact"?

2. Could there be more than one URL that needs to be extracted?

3. Does the number in brackets come after the URL or before it?

Link to comment
Share on other sites

I need the full word contact.

I've built a workaround for now which does the job

Make each url into a separate line by substituting the [ character for the newline character.

Using the custom function ExtractLine inside a script loop to pull each line and check it for "contact"

It's clumsy but it works for now. Can't spend all day solving one problem. I'd like to come back to it as I hate messy code.

Thanks

Pete

Link to comment
Share on other sites

Try a custom function:

ExtractContacts ( text )


Let ( [

pos = Position ( text ; "contact" ; 1 ; 1 ) ;

start = Position ( text ; "] " ; pos ; -1 ) + 2 ; 

end = Position ( text & "[" ; "[" ; pos ; 1 ) 

] ;

Case ( pos ; 

Middle ( text ; start ; end - start )

& ¶ &

ExtractContacts ( Right ( text ; Length ( text ) - end ) )

)

)

Link to comment
Share on other sites

This topic is 5796 days old. Please don't post here. Open a new topic instead.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use.