Hi All,
Wondering if someone could help me with trimming strings of data. I have
results being spit out by a query that will always return results similar to
this, same amount of numbers all of the time always in this format:
100030_200606
100030_200605
100030_200604
100030_200603
What I am trying to do is figure out a way to set variables for 3 different
parts of this output (id,year,month) so I can insert 3 seperate fields into my
database. I will use the first record that is output in my example below:
1. I need to extract the 100030 and set that as my id in the db
2. I need to extract the 2006 and set that as my year in the db
3. I need to extract the 06 and set that as my month in the db
I don't know if I need to use the trim function or not and if I do I'm not too
sure how to make it work. Thanks in advance for any help on this.
DJ5MD - 28 Jul 2006 16:28 GMT
You could use this if the length of the values is ALWAYS the same:
<cfset myid = #Left(FormField, 6)#>
[i]Takes the first 6 chars from the left most position[/]
<cfset myyear = #Mid(FormField, 8, 4)#>
[i]Takes 4 chars starting from position 8[/i]
<cfset mymonth = #right(FormField, 2)>
[i]Takes the first 2 chars from teh right most position[/i]
Dan Bracuk - 28 Jul 2006 16:32 GMT
If the length is not always the same, treat it as a list delimited by the underscore. Then you use the same approach that DJ5MD suggested to get the year and month.
brianism - 28 Jul 2006 16:39 GMT
Thanks DJ5MD, that did exactly what I needed!