Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Making 9999999999999999 look like 9999 9999 9999 9999 1

Status
Not open for further replies.

hautnueil

Programmer
Feb 21, 2002
25
0
0
US
What CF function(s) would I need to make

9999999999999999 look like 9999 9999 9999 9999

I need to grab credit card data out of my Access DB and dump it in an Excel Sheet so that it is more readable.

I got around the exponential display, but I'm at a loss for inserting spaces every fourth digit. (early morning brain cramp)

Any help or clues anyone could give me is IMMENSELY appreciated.

I'm on a deadline - tick-tock-tick-tock... Good thing I can manage pressure...
 
Not very elegant, but this will work. You can probably make a loop out of it.

<cfset MyNumber=&quot;1234123412341234&quot;>

<cfset MyNumber=Insert(&quot; &quot;,MyNumber,4)>
<cfset MyNumber=Insert(&quot; &quot;,MyNumber,9)>
<cfset MyNumber=Insert(&quot; &quot;,MyNumber,14)> Calista :-X
Jedi Knight,
Champion of the Force
 
A regular expression would work nicely

=== START CODE EXAMPLE ===
<cfset ccNum = 9999999999999999>

<cfoutput>
#ReReplace(variables.ccNum, &quot;(
Code:
[
0-9
Code:
]
{4})&quot;
, &quot;\1 &quot;, &quot;ALL&quot;)#
</cfoutput>
=== END CODE EXAMPLE ===

This may leave one extra space on the end:
&quot;9999 9999 9999 9999 &quot;
If you want to remove the extra space simply add the Trim() function

=== START CODE EXAMPLE ===
<cfoutput>
#Trim(ReReplace(variables.ccNum, &quot;(
Code:
[
0-9
Code:
]
{4})&quot;
, &quot;\1 &quot;, &quot;ALL&quot;))#
</cfoutput>
=== END CODE EXAMPLE === - tleish
 
Thanks Calista and -tleish...

Both solutions work like a charm.
 
Thanks, tleish! I knew there was a better way. You forced me to do some research to understand your response, and that's a good thing. [thumbsup] Calista :-X
Jedi Knight,
Champion of the Force
 
Pretty cool -tleish!

Is the &quot;\1&quot; a backreference like the &quot;$1&quot; in Perl?

And, if I may add, this forum is grrrrrrreaaaaaat!


 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top