Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Westi on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Ignore text after carriage return

Status
Not open for further replies.

itsuit

IS-IT--Management
Apr 23, 2002
53
US
I have a database field ("DESCRIPTION") that allows carriage returns when the data is being entered. In my report, I only want to include text entered prior to the first carriage return (discarding everything after that). Can anyone help with the formula for this?

Thanks in advance.
 
Normally you could use the instr() function to test for the existence of a substring and then use the left() function to get the first part of the string. Example:

Left("I SHOT THE SHERIFF",Instr("I SHOT THE SHERRIFF","THE")-1)

returns "I SHOT ".

I tested with with chr(13), which is a carriage return, wothout success. Is there some other charcter(s) we can look for?


Software Sales, Training, Implementation and Support for Exact Macola, eSynergy, and Crystal Reports
 
I have never tried this with a field in which there is text after "trailing spaces" (carriage returns) but it might work.

Try RTrim({table.field}) -- basic syntax

or

TrimRight({table.field}) -- Crystak syntax

-- Jason
"It's Just Ones and Zeros
 
Try:

left({table.string}, instr({table.string},chr(13))-3)

The chr(13) appears to take 3 spaces.

-LB
 
Thanks for the prompt replies, folks!

jdemmi's suggestion worked perfectly - I didn't think that TrimRight would take carriage returns into account, but it did!

Thanks again.
 
I spoke too soon - when exporting to a tab-separated text file, I noticed that the carriage return is still appearing in some records.

lbass, I tried your suggestion but the problem is that not *all* records have a carriage return, so I get a zero-length string error on those records without the carriage return.

Any other suggestions for handling that?

Thanks!
 
I'm assuming you want the whole string when there is no carriage return:

if instr({table.string},chr(13)) <> 0 then
left({table.string}, instr({table.string},chr(13))-3) else
{table.string}

-LB
 
It seems this has all been overcomplicated.

Replace all carriage returns with nothing, just use the following:

replace({table.string}, chr(13),"")

You might also want to make sure that you eliminate line feeds:

replace(replace({table.string}, chr(13),""),(chr(10),"")

As for finding carriage returns in a tab seperated fiel, they will have thyem at the end of each row, a tab seperated seperates columns with tabs, rows with carriage returns.

-k
 
synapsevampire -

Worked like a charm.

Thanks to everyone for your suggestions.
 
Your original requirements were:

In my report, I only want to include text entered prior to the first carriage return (discarding everything after that).

I think SV's solution would only remove the return, not remove text occuring after the return.

-LB
 
Hi !

This is not a 100 % solution, but if you start with replacing the carriage return and line feeds with a character that you is almost certain of not exists in your string. For example a ^.

Then your formula could look like this:

if instr({table.string},chr(13)) <> 0 then
Split(replace(replace({table.string}, chr(13),"^"),(chr(10)),"^"), "^")[1]
else
{table.string}

The split will help you get the part prior to the first carriage return.

(The split function came with version 8)

/Goran
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top