Jump to content

Cut carriage return from text field¶


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

Recommended Posts

I have a text field where I want to be able to remove any carriage returns which are at the end of the text (while keeping carriage returns which are in the middle). To get rid of one is easy:

case(right(field;1)= "¶" ; left (field;length(field)-1)

However, there may be more than one carriage return at the end of the text. It is quite common to have 2 or 3, but on occasions there have been 20+.

So, is there a tidy way to remove all these extra carriage returns using a calculation?

An example of the text in the field (using ¶ as a carrriage return):)

"Price Guide: £20¶

double £40¶

suite $80¶

¶"

In the above text example I would want to remove the final four paragraph characters.

Link to comment
Share on other sites

I have a recursive custom function to do just that.

xCF_RemoveFormat_Full ( text )

Let( [ Format = Trim ( TextFormatRemove ( If ( Right ( Text ; 1 ) = "¶" ; Replace ( Text ; Length ( Text ) ; 1 ; "" ) ; Text ) ) )



];



If ( Right ( Format ; 1 ) = "¶" ; xCF_RemoveFormat_Full ( Format ); Format ) )

Edited by Guest
Link to comment
Share on other sites

Those using v7 can also use the following which was originally posted by comment back in '05.

That's a neat idea.

Or you could use PatternCount() to deal only with the last occurence, something like:

Let ( [

crRun = "����������" ;

textCR = text & crRun ;

last = PatternCount ( textCR ; crRun ) ;

pos = Position ( textCR ; crRun ; 1 ; last )

] ;

Left ( textCR ; pos - 1 )

)

Note: n carriage returns in 'crRun' will remove up to n-1 carriage returns - always at the end.

full topic can be found at: http://fmforums.com/forum/showtopic.php?tid/168001/post/168343

Link to comment
Share on other sites

This topic is 6210 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.