House of Fusion
Home of the ColdFusion Community

Search cf-talk

December 02, 2008

<<   <   Today   >   >>
Su Mo Tu We Th Fr Sa
   1 2 3 4 5 6
7 8 9 10 11 12 13
14 15 16 17 18 19 20
21 22 23 24 25 26 27
28 29 30 31       

Search over 2,500 ColdFusion resources here  >>>      
Home /  Groups /  ColdFusion Talk (CF-Talk)

extracting numbers from a string

  << Previous Post |  RSS |  Sort Oldest First |  Sort Latest First |  Subscribe to this Group Next >> 
Top  |   Reply  |   Original Post  |   RSS Feed  |   Subscribe to this Group
Author:
Matthew Smith
09/06/2008 10:51 AM

I am parsing a paypal history(csv) to update records in a databse. Here is an example of one of the values from one line of the csv: "#47-Pepper - 10 votes" The first number is the primary key from the db. I can parse it, but I am limited to 4 digits long with my solution, and it is not very elegant.  Here's what I have: <cfset primarykey = mid(detail, 3, 1)> <cfif isnumeric(mid(detail, 4, 1))>    <cfset primarykey = primarykey & mid(detail, 4, 1)> </cfif> <cfif isnumeric(mid(detail, 5, 1))>    <cfset primarykey = primarykey & mid(detail, 5, 1)> </cfif>   <cfif isnumeric(mid(detail, 6, 1))>    <cfset primarykey = primarykey & mid(detail, 6, 1)> </cfif> Is there a better way to do what I am trying to do? Thanks.

Top  |   Parent  |   Reply  |   Original Post  |   RSS Feed  |   Subscribe to this Group
Author:
Andy Matthews
09/06/2008 02:55 PM

If you're looking to get the number at the beginning of the string: <cfset primayKey = REMatchNoCase('^#[0-9]+',str)> That will return an array with, using your current string, a single index. If you're wanting to get ALL numbers from the string: <cfset primayKey = REMatchNoCase('[0-9]+',str)> That returns the same array with, using your current string, two indexes. I am parsing a paypal history(csv) to update records in a databse. Here is an example of one of the values from one line of the csv: "#47-Pepper - 10 votes" The first number is the primary key from the db. I can parse it, but I am limited to 4 digits long with my solution, and it is not very elegant. Here's what I have: <cfset primarykey = mid(detail, 3, 1)> <cfif isnumeric(mid(detail, 4, 1))>    <cfset primarykey = primarykey & mid(detail, 4, 1)> </cfif> <cfif isnumeric(mid(detail, 5, 1))>    <cfset primarykey = primarykey & mid(detail, 5, 1)> </cfif>   <cfif isnumeric(mid(detail, 6, 1))>    <cfset primarykey = primarykey & mid(detail, 6, 1)> </cfif> Is there a better way to do what I am trying to do? Thanks.

Top  |   Parent  |   Reply  |   Original Post  |   RSS Feed  |   Subscribe to this Group
Author:
Matthew Smith
09/06/2008 04:14 PM

><cfset primayKey = REMatchNoCase('^#[0-9]+',str)> I get an error when running that.  I tried: <cfset primayKey = REMatchNoCase('^##[0-9]+',str)> but that just results in an empty array.


<< Previous Thread Today's Threads Next Thread >>

Mailing Lists