Print Page | Close Window

Strip out a carriage return from string

Printed From: Crystal Reports Book
Category: Crystal Reports 9 through 2020
Forum Name: Technical Questions
Forum Discription: Formulas, charting data, Crystal syntax, etc.
URL: http://www.crystalreportsbook.com/forum/forum_posts.asp?TID=21172
Printed Date: 05 May 2024 at 7:47am


Topic: Strip out a carriage return from string
Posted By: adavis
Subject: Strip out a carriage return from string
Date Posted: 20 Nov 2014 at 3:27am
I have a string field where several of the values contain carriage returns or something that is causing a line break when I export out the report to a CSV. I need to strip out whatever is causing this to happen.

The field is table.billing_address

My initial thought was to create a formula field to replace the carriage return with "", but I cannot figure out how to do that.

Has anyone else encountered this before? Ideas for solving this problem?



Replies:
Posted By: adavis
Date Posted: 20 Nov 2014 at 4:16am
Found a solution. I will share it here in case anyone else has the same problem.

Created a new Formula:

stringvar output := {TABLE_NAME.FIELD_NAME};
output := Trim(output); //get rid of leading & trailing spaces
output := Replace(output,Chr(13),''); //get rid of line feed character
output := Replace(output,Chr(10),''); //get rid of carriage return character

//add any other special characters you want to strip out.


Posted By: DBlank
Date Posted: 20 Nov 2014 at 4:17am
REPLACE(replace({table.billing_address},CHR(13)," "),CHR(10)," ")


Posted By: adavis
Date Posted: 20 Nov 2014 at 4:32am
DBlank,

Thanks for the response. I didn't know about CHR values until today. I found a list of special characters to use as a reference in the future:
Character 8 - Chr(8): Backspace
Character 9 - Chr(9): Tab (vbTab)
Character 10 - Chr(10): Line Feed Return (vbLf)
Character 11 - Chr(11): Shift+Enter (vbVerticalTab)
Character 12 - Chr(12): Page Break (vbFormFeed)
Character 13 - Chr(13): Carriage Return
Character 14 - Chr(14): Column Break
Character 15 - Chr(15): Shift In
Character 32 - Chr(32): Space

Do you know of a good resource I can bookmark to reference for other special characters?


Posted By: DBlank
Date Posted: 20 Nov 2014 at 7:32am

you can search ASCII charts to get a list




Print Page | Close Window