Feb 12, 2002 #1 shukui Technical User Apr 27, 2001 28 US Hi all, How can I manipulate string like from "acthaychyaggdsdy" to "act hay chy agg dsd y" or change above string to a list or an array containing above elements. Thanks, Stephen
Hi all, How can I manipulate string like from "acthaychyaggdsdy" to "act hay chy agg dsd y" or change above string to a list or an array containing above elements. Thanks, Stephen
Feb 12, 2002 #2 Guest_imported New member Jan 1, 1970 0 Browse at the string functions in the online docs . You need to extract one letter at a time. You could do: <cfset string = "acthaychyaggdsdy"> <cfset word = ""> <cfset j = 1> <cfset wordarray = arrayNew(1)> <cfloop index="i" from="1" to="#len(string)#"> <cfset word = Insert(mid(string, i, 1), word, len(word))> <cfif i mod 3 EQ 0> <cfset wordarray[j] = word> <cfset j = j + 1> <cfset word = ""> </cfif> </cfloop> <cfoutput> <br> <cfloop index="i" from="1" to="#arraylen(wordarray)#"> #wordarray#<br> </cfloop> </cfoutput> There is a bug in the code. It doesn't get the last character. I'll leave the fix up to you. Upvote 0 Downvote
Browse at the string functions in the online docs . You need to extract one letter at a time. You could do: <cfset string = "acthaychyaggdsdy"> <cfset word = ""> <cfset j = 1> <cfset wordarray = arrayNew(1)> <cfloop index="i" from="1" to="#len(string)#"> <cfset word = Insert(mid(string, i, 1), word, len(word))> <cfif i mod 3 EQ 0> <cfset wordarray[j] = word> <cfset j = j + 1> <cfset word = ""> </cfif> </cfloop> <cfoutput> <br> <cfloop index="i" from="1" to="#arraylen(wordarray)#"> #wordarray#<br> </cfloop> </cfoutput> There is a bug in the code. It doesn't get the last character. I'll leave the fix up to you.
Feb 12, 2002 Thread starter #3 shukui Technical User Apr 27, 2001 28 US Thank you A440Guy, I figured it out this way: <cfset string = "acthaychyaggdsdy"> <CFLOOP INDEX="i" FROM="#len(string)#" TO="1" step ="-1"> <cfif (i mod 3) EQ 0> <cfset string = Insert(' ', string, #i#)> </cfif> </CFLOOP> Thank you for remind me the Insert() funcion. Upvote 0 Downvote
Thank you A440Guy, I figured it out this way: <cfset string = "acthaychyaggdsdy"> <CFLOOP INDEX="i" FROM="#len(string)#" TO="1" step ="-1"> <cfif (i mod 3) EQ 0> <cfset string = Insert(' ', string, #i#)> </cfif> </CFLOOP> Thank you for remind me the Insert() funcion.
Feb 12, 2002 #4 Guest_imported New member Jan 1, 1970 0 Pretty clever! OK, for those of you who are reading this, here is the solution to fix the bug mentioned above. Insert these lines after the end of the first CFLOOP: <cfif word NEQ ""> <cfset wordarray[j] = word> </cfif> Upvote 0 Downvote
Pretty clever! OK, for those of you who are reading this, here is the solution to fix the bug mentioned above. Insert these lines after the end of the first CFLOOP: <cfif word NEQ ""> <cfset wordarray[j] = word> </cfif>
Feb 12, 2002 #5 tleish Programmer Jan 17, 2001 619 US What about using a regular expression instead <CFSET string = "acthaychyaggdsdy"> <CFSET string = Trim(ReReplace(string, "( Code: [ Code: [ :alpha: Code: ] Code: ] {1,3})", "\1 ", "ALL"))> - tleish Upvote 0 Downvote
What about using a regular expression instead <CFSET string = "acthaychyaggdsdy"> <CFSET string = Trim(ReReplace(string, "( Code: [ Code: [ :alpha: Code: ] Code: ] {1,3})", "\1 ", "ALL"))> - tleish
Feb 13, 2002 #6 Guest_imported New member Jan 1, 1970 0 That's much more compact. However, it _is_ harder to understand and should be accompanied by a cogent comment. Upvote 0 Downvote
That's much more compact. However, it _is_ harder to understand and should be accompanied by a cogent comment.
Feb 13, 2002 Thread starter #7 shukui Technical User Apr 27, 2001 28 US Yes, that is really elegence! How does it work, by the way? Upvote 0 Downvote