Coldfusion split numbers

Posted on 2007-03-27
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
Question by:keevin
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
LVL 36

Assisted Solution

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>
<cfset vNewNum = theNum>


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

LVL 39

Expert Comment

ID: 18800105

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

Accepted Solution

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))>

LVL 36

Expert Comment

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

Featured Post

Windows Server 2016: All you need to know

Learn about Hyper-V features that increase functionality and usability of Microsoft Windows Server 2016. Also, throughout this eBook, you’ll find some basic PowerShell examples that will help you leverage the scripts in your environments!

Question has a verified solution.

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

This article provides a case study on how our local youth baseball league deployed a new website, including the platform selection, implementation and benefits to the league.
Meet the world's only “Transparent Cloud™” from Superb Internet Corporation. Now, you can experience firsthand a cloud platform that consistently outperforms Amazon Web Services (AWS), IBM’s Softlayer, and Microsoft’s Azure when it comes to CPU and …
The purpose of this video is to demonstrate how to properly insert a Vimeo Video into a WordPress site or Blog. This will be demonstrated using a Windows 8 PC. Go to your WordPress login page. This will look like the following:…
The purpose of this video is to demonstrate how to update a WordPress Site’s version. WordPress releases new versions of its software frequently and it is important to update frequently in order to keep your site secure, and to get new WordPress…

718 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