Simple regex help in coldfusion -
i have string wish remove characters based on underscores in string. instance.
i wish change
2_master bedroom_cfm to
master bedroom or
2734923ie_bedroom 2_cfm to
bedroom 2 any recomendations on how coldfusion?
coldfusion has gettoken() function, makes manipulating string delimiter (virtually delimiter) easy. assuming each string you're looking parse 2 sets of strings output master bedroom
<cfset string1 = '2_master bedroom_cfm'> <cfset firstword = listfirst(string1,' ')> <cfset firstword = gettoken(firstword,2,'_')> <cfset secondword = listlast(string1,' ')> <cfset secondword = gettoken(secondword,1,'_')> <cfoutput> #firstword# #secondword# </cfoutput> could simplify down just
<cfset string1 = '2_master bedroom_cfm'> <cfoutput> #gettoken(listfirst(string1,' '),2,'_')# #gettoken(listlast(string1,' '),1,'_')# </cfoutput> edit leigh points out in comments use
gettoken("2_master bedroom_cfm", 2, "_") this treats string list elements 2, master bedroom, , cfm
Comments
Post a Comment