Cutting a string in ColdFusion

196 views Asked by At

I have values in my query that looks like the following: Decrease with an active address (2) or Unsecured task (100) etc.

The value within the parentheses varies, it can be one, two, three digits or more because this is a count value.

I just need to get the description not the parentheses nor the value. So what I need is just:

Decrease with an active address
Unsecured task

etc.

How can I get rid of the opening (, the numeric value and the closing )?

In ColdFusion 8?

1

There are 1 answers

2
Leigh On

As Dan mentioned in the comments, one option is using reReplace() with the appropriate expression to remove any text within parenthesis:

<cfscript>
    origText = "Decrease with an active address (2)";
    newText = reReplaceNoCase(origText, "\([^)]*\)", "", "all");
    writeDump( newText );
</cfscript>

Update:

As Alex mentioned in the comments, if you just want to "cut" the string, and grab the part before the parenthesis, try something like this:

<cfscript>
    origText = "Decrease with an active address (2) plus more text after the parenthesis";
    newText = reReplaceNoCase(origText, "\([0-9]*\).*$", "", "all");
    writeOutput("<br>"& newText );
</cfscript>