FW: string manipulation

0 views
Skip to first unread message

rai...@ozemail.com.au

unread,
Sep 7, 2009, 11:28:29 AM9/7/09
to cfau...@googlegroups.com, coldfusi...@yahoogroups.com

 

 

 

 

Regards

Claude Raiola
B.Econ (Acc), B.Hot.Mngt.

Websites:

www.SAMARIS.NET

Mobile: 0414 228 948

 

From: SAMARIS Software [mailto:in...@SAMARIS.net]
Sent: Tuesday, 8 September 2009 1:27 AM
To: 'cfau...@googlegroups.com'; 'coldfusi...@yahoogroups.com'
Subject: string manipulation

 

I have many records that have an 11 digit number stored into one database field however I am wanting to break up the value to display as 11 separate values so I am wondering how do I separate the 11 digit value into 11 separate values in cold fusion

 

 

 

Regards

Claude Raiola
B.Econ (Acc), B.Hot.Mngt.

Websites:

www.SAMARIS.NET

Mobile: 0414 228 948

 

Paul Kukiel

unread,
Sep 7, 2009, 11:39:33 AM9/7/09
to cfau...@googlegroups.com

How about this:

 

<cfset number = "12345678912" />

<cfset numberStruct = {} />

<cfloop from="1" to="#len(number)#" index="i">

      <!--- display --->

      <cfoutput>

            #left(right(number,len(number)-i+1),1)#

      </cfoutput>

      <!--- make varibales --->

      <cfset numberStruct[i] = left(right(number,len(number)-i+1),1) />

</cfloop>

 

<cfdump var="#numberStruct#" />

 

Paul.

Steve Onnis

unread,
Sep 7, 2009, 12:09:20 PM9/7/09
to cfau...@googlegroups.com
thats a lot of work for not much
 
-- Make it into a list
<cfset list = REReplace("12345678901", "([0-9])", "\1,", "ALL") />
 
-- Make it into an array (CF8 only)
<cfset list = REMatch("[0-9]", "12345678901") />
 
or
 
<cfset list = listToArray(REReplace("12345678901", "([0-9])", "\1,", "ALL")) />
 
Even the example below....why wouldnt you just use MID() ?
 
 <cfset numberStruct[i] = MID(number, i, 1) />
 
Steve


From: Paul Kukiel [mailto:kuk...@gmail.com]
Sent: Tuesday, 8 September 2009 1:40 AM
To: cfau...@googlegroups.com
Subject: [cfaussie] Re: FW: string manipulation

Kevan Stannard

unread,
Sep 7, 2009, 4:29:01 PM9/7/09
to cfau...@googlegroups.com
Hi Claude

There is also a Java function that may work for you:

<cfset num = "12345678901">
<cfset digits = num.toCharArray()> 

However this does not return a normal CF array, this is a Java array of Character objects. If you want to manipulate the digits you'd probably want to convert to a normal cf array first.

<cfset digits = listToArray(arrayToList(num.toCharArray())) >

Kevan Stannard

nkosi

unread,
Sep 7, 2009, 10:35:48 PM9/7/09
to cfaussie
Or do it in the query ...

Oracle would be something like ...

SELECT substr(your_column_here, 1, 1) AS COL1,
substr(your_column_here, 2, 1) AS COL2,
substr(your_column_here, 3, 1) AS COL3,
....
substr(your_column_here, 11, 1) AS COL11
FROM your_table_here

Not that I am recommending it ... I'm just offering it as an
alternative.

Cheers
Glen
Reply all
Reply to author
Forward
0 new messages