• Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
    Dedicated community for Japanese speakers
  • 한국 커뮤니티
    Dedicated community for Korean speakers
Exit
0

Delete everything to the right of matching phrase

New Here ,
Sep 13, 2019 Sep 13, 2019

Copy link to clipboard

Copied

I'm using sendgrid's email parser to return the body of an email to my application. The problem is, if the message is a reply it also returns the original message with the reply message. What I'm trying to do is parse out the reply from the original message. To do this I think I need to find the text/characters that each major email client uses between the reply and the original message and remove the original message.

 

What I'm trying to do is use coldfusion to look at the following example text and delete out everything to the right of and including the 'On Fri, Sep 13, 2019' in the following text.

 

This is an example of a gmail reply.
"here's a test reply with multiple line breaks On Fri, Sep 13, 2019 at 5:56 PM <matt@email.com> wrote: > ---*PLEASE REPLY ABOVE THIS LINE*--- > > This is your confirmation text > I wonder how to keep the line breaks? > > > Thank you!"

 

How would this be possible in CF? If you know of any better way to accomplish this, that would be great as well.

So what I'd like to end up returning would be: "here's a test reply with multiple line breaks"

TOPICS
Advanced techniques

Views

158

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Sep 14, 2019 Sep 14, 2019

Copy link to clipboard

Copied

LATEST

Two points:

 

1. Don't worry about line breaks. ColdFusion will consider them to be characters in a string. 

 

2. You could just solve this by writing a function. Something like this:

<cfscript>

testString="here's a test reply with multiple line breaks On Fri, Sep 13, 2019 at 5:56 PM <matt@email.com> wrote: > ---*PLEASE REPLY ABOVE THIS LINE*--- > > This is your confirmation text > I wonder how to keep the line breaks? > > > Thank you!";


delimitingString="On Fri, Sep 13, 2019";

 

result=findSubstring(testString, delimitingString);
writeoutput(result);

 

/* Function to extract a substring from an input string, given a sring delimiter */
string function findSubstring (required string stringToSearch, required string delimiterString) {

    if(arguments.delimiterString is "") {
        return arguments.stringToSearch;
    }
    var searchIndex=findNoCase(arguments.delimiterString, arguments.stringToSearch);

    return left(arguments.stringToSearch,searchIndex-1);
}

</cfscript>

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Resources
Documentation