gpt4 book ai didi

coldfusion - 如何用一位数字替换前两位数字 Coldfusion

转载 作者:行者123 更新时间:2023-12-03 11:26:57 25 4
gpt4 key购买 nike

我想把前两位替换成0如果它以 0 开头,则无需更改任何内容。示例:445656 到 056....

<cfif number (BEGIN WITH?) "44">
<cfset number = Right(number , Len(number )-2) />

但这只会删除前两位数字。谢谢大家的支持

最佳答案

看起来您将“以 0 开头”的数字保留为字符串。试试这个:

<!--- // a number that does not start with zero --->
<cfset theNumber = "445656" />
<cfset theNumber = left(theNumber, 1) is 0 ? theNumber : REReplaceNoCase(theNumber, "^[0-9]{2}", 0) />
<!--- // returns 05656 --->
<cfoutput>#theNumber#</cfoutput>

<hr />

<!--- // a number that starts with zero --->
<cfset theNumber = "05656" />
<cfset theNumber = left(theNumber, 1) is 0 ? theNumber : REReplaceNoCase(theNumber, "^[0-9]{2}", 0) />
<!--- // returns 05656 --->
<cfoutput>#theNumber#</cfoutput>

如果您的号码总是以 0 或 44 开头,您可以使用

<cfset theNumber = left(theNumber, 1) is 0 
? theNumber
: REReplaceNoCase(theNumber, "^[4]{2}", 0) />

Update: Also, read the comments, there are some good points in there.

关于coldfusion - 如何用一位数字替换前两位数字 Coldfusion,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49639804/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com