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

Seperating a text field

Explorer ,
Aug 30, 2012 Aug 30, 2012

I have the following data:

1/rgrgrrtr,2/xcvxcvxcvx,3/cccc,4/thtryrytrytry,5/cvbzxcbb,6/eeeeeeeeeeeeeeee,7/nnnnnnnnnnnnnnnnnn

I can seperate the above values on the / using the:

<cfloop index = "ListElement" list = "#nenen#" delimiters = ",">

</cfloop>

The above will produce:

1/rgrgrrtr

2/xcvxcvxcvx

3/cccc

4/thtryrytrytry

5/cvbzxcbb

6/eeeeeeeeeeeeeeee

7/nnnnnnnnnnnnnnnnnn

I need to seperate each value based on the /. Placing the value before the / in a variable and the value after the / in another variable. I have not found a Cold Fusion function to do this.

The value before the / can be more than one character in length.

The value before the / would be compared against another value that contains a record number.

Thanks.

783
Translate
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
Guide ,
Aug 30, 2012 Aug 30, 2012

How about treating the resulting elements as a list as well (delimited by the forward slash):

<cfset itemID = "">

<cfset itemValue = "">

<cfloop index = "ListElement" list = "#nenen#" delimiters = ",">

<cfset itemID = listFirst(ListElement, "/")>

<cfset itemValue = listLast(ListElement, "/")

<!--- Do your comparison stuff here --->

</cfloop>

HTH,

Carl V.

Translate
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 ,
Aug 30, 2012 Aug 30, 2012

GetToken()

Translate
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
Engaged ,
Aug 30, 2012 Aug 30, 2012
LATEST

I have found an easy way to do this is treating your string segments as a ColdFusion list.  Lists in ColdFusion are nothing more than strings with delimeters.  By default the delimeter is a comma but you can change that to whatever you want.

So in your case you could do something like:

<cfset firstIndex = ListGetAt("1/rgrgrrtr",1,"/") />

<cfset firstValue = ListGetAt("1/rgrgrrtr",2,"/") />

<cfset secondIndex = ListGetAt("2/xcvxcvxcvx",1,"/") />

<cfset secondValue = ListGetAt("2/xcvxcvxcvx",2,"/") />

<cfset thirdIndex = ListGetAt("3/cccc",1,"/") />

<cfset thirdValue = ListGetAt("3/cccc",2,"/") />

etc.

Obviously you can change those variable names, use an array and keep appending values, or whatever.  What I wanted to show you is how you can use the ListGetAt function to parse those strings for you.  The BIG caveat here is that you must be sure the delimeter character (/ in your case) does not show up anywhere else in your string.  If it does that will throw things off.

Translate
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