|
|
Home /
Groups /
ColdFusion Talk (CF-Talk)
Simple List Question
Probably been covered before...Che Vilnonis 05/15/08 04:04 P >Probably been covered before...Richard White 05/15/08 04:12 P Thanks Richard... It was the len(string) statement that I was forgetting.Che Vilnonis 05/15/08 04:23 P >>How do I take a word like, "apple" and loop through each letter?Claude Schneegans 05/15/08 04:22 P You can't treat a word as a list of letters, because there's no delimiter.Jim McAtee 05/15/08 04:22 P Probably been covered before... How do I take a word like, "apple" and loop through each letter? I'd like to end up with "a.p.p.l.e". Thanks, Che >Probably been covered before... >How do I take a word like, "apple" and loop through each letter? I'd like to >end up with "a.p.p.l.e". > >Thanks, Che loop through the length of the string using len(currentString) then use the mid function to get each character: mid(currentString,loopCounter,1) Thanks Richard... It was the len(string) statement that I was forgetting. >Probably been covered before... >How do I take a word like, "apple" and loop through each letter? I'd >like to end up with "a.p.p.l.e". > >Thanks, Che loop through the length of the string using len(currentString) then use the mid function to get each character: mid(currentString,loopCounter,1) >>How do I take a word like, "apple" and loop through each letter? Try this: <CFSET word = "apple"> <CFLOOP INDEX="c" FROM="1" TO="#len(word)#"> <CFSET currentChar = mid(word,c,1)> <CFOUTPUT>currentChar = #currentChar#<BR></CFOUTPUT> </CFLOOP> -- _______________________________________ REUSE CODE! Use custom tags; See http://www.contentbox.com/claude/customtags/tagstore.cfm (Please send any spam to this address: piegeacon@internetique.com) Thanks. You can't treat a word as a list of letters, because there's no delimiter. Use something like: <cfset s = "apple"> <cfset t = ""> <cfloop index="i" from="1" to="#len(s)#"> <cfset t &= mid(s, i, 1) & "."> </cfloop> <cfoutput>#t#</cfoutput> > Probably been covered before... > How do I take a word like, "apple" and loop through each letter? I'd > like to > end up with "a.p.p.l.e".
|
Mailing Lists
|
Latest Fusion Authority Articles
|
||||||