Go Premium for a chance to win a PS4. Enter to Win

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 1969
  • Last Modified:

"Cut out" a set substring in Crystal Reports

I have a comment field from the database and I want to "cut out" a portion of the comment and then display the remaining string in a Crystal Report formula field.  The substring that I want to eliminate is always the same, but it may not be in the same place.  It may also not be in the comment at all.  If it appeared in the comment, it would only appear once. I could also use some help on cutting out more than one space between the remaining text strings.  For example:

DATABASE COMMENT STRING                                 WANT TO DISPLAY
'This is a comment. Other text. More text'                  'Other text. More text'
'More text. This is a comment.    Other text'               'More text. Other text'
'Other text  This is a comment.'                                  'Other text'
'More text... and more.This is a comment. More'        'More text... and more. More'
'A different comment'                                                 'A different comment'

I've already created a formula, but need the exact code.  This is pseudocode:
if string contains 'This is a comment.'
   remove 'This is a comment.' and any spaces inbetween and then display comment
else
   display comment

0
bshelby777
Asked:
bshelby777
1 Solution
 
peter57rCommented:
replace(replace({table.field}, "This is a comment.",""),"  "," ")

The outer replace() replaces two spaces with one.
0
 
bshelby777Author Commented:
Worked like a charm.  Thanks so much for your quick and accurate response.
0

Featured Post

New feature and membership benefit!

New feature! Upgrade and increase expert visibility of your issues with Priority Questions.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now