Re: Listing Words Backwords
This WebDNA talk-list message is from 2001
It keeps the original formatting.
numero = 37909
interpreted = N
texte = >As the [ListWords] context has no parameters that would allow >listing in reverse order...>>I'm looking for an extremely efficient bit of code that will allow >me to loop through words in a string in reverse order.>>I have created my own solution, but I have a new site that I'll need >to use this on every page so I am wondering if there might be a more >streamlined method of doing this, or just something I may have >overlooked in the docs. My solution uses a combination of two >listwords loops, several interpret tags, and a numeric loop to>>do an 'artificial array'. I'd like to slim this down if it's at all possible.Michael,The basic idea is this[text]reversed=[/text][listwords words=a,b,c,d,e][text]reversed=[word],[reversed][/text][/listwords]Don't worry about the extra , at the end of reversed, it wont hurt a thing.Here is some code that I tried working on for you, but ran out of time, it almost works ;)I think I've got the indirection wrong by a little bit.HTHs-Sam[text]x=a,b,c,d,e[/text][include file=flipwords.inc&flipwords=x&flipdelimiters=,]X: [x]
--flipwords.inc:[listwords words=[interpret][[flipwords]][/interpret]&delimiters=[interpret][[flipdelimiters]][/interpret]][flipwords]. [text][flipwords][/text]. [word]. [index] ![showif [index]=1][text][flipwords]=[/text][/showif] [text][flipwords]=[delimiter][word][text][flipwords][/text][/text][flipwords]. [text][flipwords][/text]. [word]. [index]
[/listwords]>>My solution is an include file that will flip the words in a text variable.>Usage:>[text]wordlist=a,b,c,d,e[/text]>[include file=^flipwords.inc&flipwords=wordlist&flipdelimiters=,]>[wordlist]>>>The output is e,d,c,b,a>>Code for flipwords.inc:>>------->[showif [flipwords]![raw][flipwords][/raw]][!]>[/!][showif [flipwords]!][!]>[/!][showif [interpret][[flipwords]][/interpret]!][!]>[/!][text]flipwordsd=[if ([flipdelimiters]![raw][flipdelimiters][/raw])|(>[flipdelimiters]!)][then][flipdelimiters][/then][else], >.[/else][/if][/text][!]>[/!][math show=f]flipwordsx=[countwords >delimiters=[flipwordsd]][interpret][[flipwords]][/interpret][/countwords][/math]>[!]>[/!][math show=f]flipwordsy=[flipwordsx]+1[/math][!]>[/!][listwords >words=[interpret][[flipwords]][/interpret]&delimiters=[flipwordsd]][!]>[/!] [math show=f]flipwordsy=[flipwordsy]-1[/math][!]>[/!] [text show=t]flipwords[flipwordsy]=[word][delimiter][/text][!]>[/!][/listwords][!]>[/!][text][flipwords]=[loop >start=1&end=[flipwordsx]][interpret][flipwords[index]][/interpret][/loop][/text]>[!]>[/!][/showif][!]>[/!][/showif][!]>[/!][/showif]>-------------------------------------------------------------------This message is sent to you because you are subscribed to the mailing list
.To unsubscribe, E-mail to: To switch to the DIGEST mode, E-mail to Web Archive of this list is at: http://search.smithmicro.com/
Associated Messages, from the most recent to the oldest:
>As the [listwords] context has no parameters that would allow >listing in reverse order...>>I'm looking for an extremely efficient bit of code that will allow >me to loop through words in a string in reverse order.>>I have created my own solution, but I have a new site that I'll need >to use this on every page so I am wondering if there might be a more >streamlined method of doing this, or just something I may have >overlooked in the docs. My solution uses a combination of two >listwords loops, several interpret tags, and a numeric loop to>>do an 'artificial array'. I'd like to slim this down if it's at all possible.Michael,The basic idea is this[text]reversed=[/text][listwords words=a,b,c,d,e][text]reversed=[word],[reversed][/text][/listwords]Don't worry about the extra , at the end of reversed, it wont hurt a thing.Here is some code that I tried working on for you, but ran out of time, it almost works ;)I think I've got the indirection wrong by a little bit.HTHs-Sam[text]x=a,b,c,d,e[/text][include file=flipwords.inc&flipwords=x&flipdelimiters=,]X: [x]
--flipwords.inc:[listwords words=[interpret][[flipwords]][/interpret]&delimiters=[interpret][[flipdelimiters]][/interpret]][flipwords]. [text][flipwords][/text]. [word]. [index] ![showif [index]=1][text][flipwords]=[/text][/showif] [text][flipwords]=[delimiter][word][text][flipwords][/text][/text][flipwords]. [text][flipwords][/text]. [word]. [index]
[/listwords]>>My solution is an include file that will flip the words in a text variable.>Usage:>[text]wordlist=a,b,c,d,e[/text]>[include file=^flipwords.inc&flipwords=wordlist&flipdelimiters=,]>[wordlist]>>>The output is e,d,c,b,a>>Code for flipwords.inc:>>------->[showif [flipwords]![raw][flipwords][/raw]][!]>[/!][showif [flipwords]!][!]>[/!][showif [interpret][[flipwords]][/interpret]!][!]>[/!][text]flipwordsd=[if ([flipdelimiters]![raw][flipdelimiters][/raw])|(>[flipdelimiters]!)][then][flipdelimiters][/then][else], >.[/else][/if][/text][!]>[/!][math show=f]flipwordsx=[countwords >delimiters=[flipwordsd]][interpret][[flipwords]][/interpret][/countwords][/math]>[!]>[/!][math show=f]flipwordsy=[flipwordsx]+1[/math][!]>[/!][listwords >words=[interpret][[flipwords]][/interpret]&delimiters=[flipwordsd]][!]>[/!] [math show=f]flipwordsy=[flipwordsy]-1[/math][!]>[/!] [text show=t]flipwords[flipwordsy]=[word][delimiter][/text][!]>[/!][/listwords][!]>[/!][text][flipwords]=[loop >start=1&end=[flipwordsx]][interpret][flipwords[index]][/interpret][/loop][/text]>[!]>[/!][/showif][!]>[/!][/showif][!]>[/!][/showif]>-------------------------------------------------------------------This message is sent to you because you are subscribed to the mailing list .To unsubscribe, E-mail to: To switch to the DIGEST mode, E-mail to Web Archive of this list is at: http://search.smithmicro.com/
Samuel Renkert
DOWNLOAD WEBDNA NOW!
Top Articles:
Talk List
The WebDNA community talk-list is the best place to get some help: several hundred extremely proficient programmers with an excellent knowledge of WebDNA and an excellent spirit will deliver all the tips and tricks you can imagine...
Related Readings:
Anyone on OSX updated to iTools 5.018? (2000)
Passing Cart variable to subdirectory files? (1997)
Re:WebCatalog vidoes (was: Prices Dropped) (1998)
[BULK] [WebDNA] triggers.db "next execute" fails to update (2012)
Formating found categories (1997)
Listfiles not listing mounted volume (2002)
Re:Merging databases (1997)
WebCatalog can't find database (1997)
emailer setup (1997)
Sum of [founditems] ? (2004)
WebCat2b12plugin - [search] is broken ... not! (1997)
transaction logging (2002)
Reversed words (1997)
WebCat2 beta FTP site (1997)
[OT] Weird returned mail - whaddya think? (2002)
WebCat for mass emailings (1997)
Development terminated. (1998)
Resume Catalog ? (1997)
PCS Frames (1997)
Latin Characters (1998)