• Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
    Dedicated community for Japanese speakers
  • 한국 커뮤니티
    Dedicated community for Korean speakers
Exit
0

Help with trimming string

Participant ,
Jul 28, 2006 Jul 28, 2006

Copy link to clipboard

Copied

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.
TOPICS
Advanced techniques

Views

251

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Guest
Jul 28, 2006 Jul 28, 2006

Copy link to clipboard

Copied

You could use this if the length of the values is ALWAYS the same:

<cfset myid = #Left(FormField, 6)#>
Takes the first 6 chars from the left most position

<cfset myyear = #Mid(FormField, 8, 4)#>
Takes 4 chars starting from position 8

<cfset mymonth = #right(FormField, 2)>
Takes the first 2 chars from the right most position

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Jul 28, 2006 Jul 28, 2006

Copy link to clipboard

Copied

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.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Participant ,
Jul 28, 2006 Jul 28, 2006

Copy link to clipboard

Copied

LATEST
Thanks DJ5MD, that did exactly what I needed!

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Resources
Documentation