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

Backup Your Microsoft Windows Server®

Backup all your Microsoft Windows Server – on-premises, in remote locations, in private and hybrid clouds. Your entire Windows Server will be backed up in one easy step with patented, block-level disk imaging. We achieve RTOs (recovery time objectives) as low as 15 seconds.

Question has a verified solution.

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

Suggested Solutions

Introduction In this tutorial, I'll explain how to create an animated progress meter in a wireframe prototype developed using Axure RP 7.0 - a leading prototyping tool for designing web sites and software. (For more information about Axure and gett…
When it comes to showing a 404 error page to your visitors, you do not want that generic page to show, and you especially do not want your hosting provider’s ad error page to show either. In this article, I will show you how to enable the custom 40…
The purpose of this video is to demonstrate how to automatically show related posts at the bottom of a blog post in WordPress. This will be demonstrated using a Windows 8 PC. Plugin “Yet Another Related Posts Plugin” will be used. Go to your…
The purpose of this video is to demonstrate how to exclude a particular blog category from the main blog page. This is can be used when a category already has its own tab, or you simply want certain types of posts not to show up on the main blog. …

786 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