ColdFusion - String Remove characters after specific place
The length of the string is always formatted as follows - but varies in length.
Add: BLLAHHH Blahhh Blahhhhh Blahhh Det: HSD03 Evt: F2014999999 NOTICE. This message is intended ONLY for the use of the person or organization named above and may contain information that is confidential or legally privileged. Blahhh blahhh blahhh
I am trying to get only data ending at the end of the number
Add: BLLAHHH Blahhh Blahhhhh Blahhh Det: HSD03 Evt: F2014999999
I've tried many string functions with great luck.
The code below allows me to:
Add: BLLAHHH Blahhh Blahhhhh Blahhh Det: HSD03 Evt: F2014999999 NOTICE
<cfset string = "#textbody#">
<br>
<cfset firstPiece = listGetAt(string, 1, "-")>
[ [ <cfoutput>#firstPiece#</cfoutput> ] ]
source to share
function trimToLastEndWithDigit(str) {
var noticePos = find(" NOTICE -", str);
return left(str, noticePos);
}
str = "Add: BLLAHHH Blahhh Blahhhhh Blahhh Det: HSD03 Evt: F2014999999 NOTICE - This communication is intended ONLY for the use of the person or entity named above and may contain information that is confidential or legally privileged. Blahhh Blahhh Blahhh";
writeOutput(trimToLastEndWithDigit(str));
http://www.trycf.com/scratch-pad/pastebin?id=c9N8NEUD
I've tried using regex to meet your needs before, but what you need is much simpler, so please ignore the function name.
source to share
You can use Regex like this
Your line:
<cfset testString = "Add: BLLAHHH Blahhh Blahhhhh Blahhh Det: HSD03 Evt: F2014999999 NOTICE - This communication is intended ONLY for the use of the person or entity named above and may contain information that is confidential or legally privileged. Blahhh Blahhh Blahhh"/>
Regex:
<cfset testSt = ReReplace(testString,"NOTICE.*","")>
Output:
Add: BLLAHHH Blahhh Blahhhhh Blahhh Det: HSD03 Evt: F2014999999
source to share
Got this I guess ...
TextBody:
Add: BLLAHHH Blahhh Blahhhhh Blahhh Det: HSD03 Evt: F2014999999 NOTICE. This message is intended ONLY for the use of the person or organization named above and may contain information that is confidential or legally privileged. Blahhh blahhh blahhh
<cfset fp = "#textbody#" />
<cfoutput>#REReplace(fp, "NOTICE(.*)", "NOTICE")#</cfoutput>
<cfset newstr = "#REReplace(fp, "NOTICE(.*)", "NOTICE")#">
<cfset final = left(newstr, len(newstr) -7)>
[<b>#final#</b>]
source to share