Solved

Coldfusion split numbers

Posted on 2007-03-27
4
402 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
  • 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

Complete VMware vSphere® ESX(i) & Hyper-V Backup

Capture your entire system, including the host, with patented disk imaging integrated with VMware VADP / Microsoft VSS and RCT. RTOs is as low as 15 seconds with Acronis Active Restore™. You can enjoy unlimited P2V/V2V migrations from any source (even from a different hypervisor)

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Restrict IIS Website without Windows login 7 54
AD LDS, AD FS, RODC, LDAP access for 3rd party vendors? 5 85
Column Spacing 3 56
app server have enough resources... 2 21
In our day to day coding, how many times have we come across a necessity to check whether a URL is a broken link or not? For those of you that answered countless and are using ColdFusion like myself, then this article is for you.  It will show yo…
Have you ever sent email via ColdFusion and thought of tracking this mail to capture the exact date and time when the message was opened ?  If yes, then this article is for you ! First we need a table user_email with columns user_id , email , sub…
The purpose of this video is to demonstrate how to set up basic WordPress SEO. This will be demonstrated using a Windows 8 PC. The plugin used will be WordPress SEO by Yoast. Go to your WordPress login page. This will look like the following: myw…
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…

919 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

Need Help in Real-Time?

Connect with top rated Experts

14 Experts available now in Live!

Get 1:1 Help Now