【问题标题】:Cutting a string in ColdFusion在 ColdFusion 中切割字符串
【发布时间】:2016-12-19 22:20:39
【问题描述】:

我的查询中有如下所示的值: Decrease with an active address (2)Unsecured task (100)

括号内的值不同,可以是一位、两位、三位或更多,因为这是一个计数值。

我只需要获取描述而不是括号或值。 所以我需要的只是:

Decrease with an active address
Unsecured task

等等

如何去掉开头(、数值和结尾)

在 ColdFusion 8 中?

【问题讨论】:

  • reReplace()。或者,如果你想要的东西总是在最后,left()find() 的组合将起作用。

标签: coldfusion coldfusion-8


【解决方案1】:

正如丹在 cmets 中提到的,一种选择是使用 reReplace()remove any text within parenthesis 的适当表达式:

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

更新:

正如 cmets 中提到的Alex,如果您只想“剪切”字符串,并抓住括号之前的部分,请尝试以下操作:

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

【讨论】:

  • 如果您只想删除带有数字的尾括号(如问题中所述),请使用\([0-9]*\)$作为reReplaceNoCase中的第二个参数。
  • @Alex - 这是一个很好的观点。我把它读作“删除它”,但看看标题,你的建议可能更接近标记。
猜你喜欢
  • 1970-01-01
  • 2014-09-10
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多