Jump to content
Sign in to follow this  
philipcaplan

Extracting text fails at last line

Recommended Posts

Hello All

I have a text field called "bigtextfield" which contains many lines of "tagged text" items of which the following are just three:

<>Charlie Anylength

<>ca@adomain.com

<>sometext

I have a calculation field of the following format, which successfully does what I want, which is to "parse" the contents of the above field splitting the text of each <> into a separate field:

Let ( [

start = Position ( bigtextfield ; "<>" ; 1 ; 1 ) + Length ( "<>" ) ;

end = Position ( bigtextfield ; "¶" ; start ; 1 )

] ;

Middle ( bigtextfield ; start ; end - start )

)

However, it fails for the final line of "bigtextfield" because that one doesn't end with a return ("¶")!!

Can someone give me a version which works even for a line which is followed by nothing!

Many Thanks.

Share this post


Link to post
Share on other sites

Try:


Let ( [

start = Position ( bigtextfield ; "<>" ; 1 ; 1 ) + Length ( "<>" ) ;

end = Position ( bigtextfield & ¶ ; ¶ ; start ; 1 )

] ;

Middle ( bigtextfield ; start ; end - start )

)

Share this post


Link to post
Share on other sites

Thank you, comment. That seems to work nicely!

The only time it doesn't work is if I have a typo in the name of the <> being extracted, in which case instead of being left blank, it seems to pick up the value of another <>!!

Can you suggest a way to catch this?

Thanks again.

Share this post


Link to post
Share on other sites

Let ( [

pos = Position ( bigtextfield ; "<>" ; 1 ; 1 ) ;

start = pos + Length ( "<>" ) ;

end = Position ( bigtextfield & ¶ ; ¶ ; start ; 1 )

] ;

Case ( pos ; Middle ( bigtextfield ; start ; end - start ) )

)

Share this post


Link to post
Share on other sites

Thanks, once again!

It seemed to need one more ) at the end, but once that was put in it seems like it works perfectly.

Your help is much appreciated. PHILIP

Share this post


Link to post
Share on other sites

It seemed to need one more ) at the end

I don't think so.

Share this post


Link to post
Share on other sites

You're right...

The final ")" was of course in your code, but I failed to include it when copying-and-pasting it.

My apologies!

Share this post


Link to post
Share on other sites

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
Sign in to follow this  

×

Important Information

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