• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 428
  • Last Modified:

Coldfusion split numbers

Hi i've got some condition to write in coldfusion was wondering if someone can help.

I've got a number 5149687, i need to check if the fourth digit is nine. If it's nine then i will need to replace it by 6, thus the new number will look like 5146687.

Thanks in advance
0
keevin
Asked:
keevin
  • 2
  • 2
2 Solutions
 
SidFishesCommented:

<cfset theNum = 5149687>
<cfset vFirst = left(theNum, 4)>
<cfset vlast = right(theNum, 3)>
<cfset vChk = right(vFirst, 1)>

<cfif vChk eq 9>
<cfset vNewNum = left(theNum, 3) & 6 & vLast>
<cfelse>
<cfset vNewNum = theNum>
</cfif>

#vNewNum#

clunky and I'm sure there's a better way but I can' think of one before my first coffee...

0
 
gdemariaCommented:

<cfif mid(theNum,4,1) eq "9">
  <cfset theNum = left(theNum,3) & "9" & mid(theNum,5,len(theNum))>
</cfif>
0
 
gdemariaCommented:

oops, you wanted to replace the 9 with a 6... type-o

<cfif mid(theNum,4,1) eq "9">
   <cfset theNum = left(theNum,3) & "6" & mid(theNum,5,len(theNum))>
</cfif>

<cfoutput>#theNum#</cfoutput>
0
 
SidFishesCommented:
see told you someone would have a better way .. :)
0

Featured Post

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

  • 2
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now