Copy link to clipboard
Copied
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.
Copy link to clipboard
Copied
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.
Copy link to clipboard
Copied
GetToken()
Copy link to clipboard
Copied
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.