Solved

Coldfusion split numbers

Posted on 2007-03-27
4
408 Views
Last Modified: 2013-12-24
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
Comment
Question by:keevin
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
  • 2
4 Comments
 
LVL 36

Assisted Solution

by:SidFishes
SidFishes earned 25 total points
ID: 18799918

<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
 
LVL 39

Expert Comment

by:gdemaria
ID: 18800105

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

Accepted Solution

by:
gdemaria earned 100 total points
ID: 18800119

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
 
LVL 36

Expert Comment

by:SidFishes
ID: 18800198
see told you someone would have a better way .. :)
0

Featured Post

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Objective of This Article In 1990’s, when I was a budding software professional, I had a lot of confusion about which stream or technology, I had to choose to build my career. In those days, I had lot of confusion like whether to choose System so…
Lease-to-own eliminates the expenditure of hardware replacement and allows you to pay off the server over time. Usually, this is much cheaper than leasing servers. Think of lease-to-own as credit without interest.
The purpose of this video is to demonstrate how to Import and export files in WordPress. This will be demonstrated using a Windows 8 PC. Go to your WordPress login page. This will look like the following: mywebsite.com/wp-login.php : Click on Too…
The purpose of this video is to demonstrate how to set up the permalinks on a WordPress Website. This will be demonstrated using a Windows 8 PC. Go to your WordPress login page. This will look like the following: mywebsite.com/wp-login.php : Go t…

730 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question