connor2k

Jar Jar Sucks

Mar 25th, 2011
160
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. <cffunction name="getSignInfo" returntype="struct">
  2.     <cfargument name="message" type="string" required="yes">
  3.     <cfargument name="width" type="numeric" required="yes">
  4.     <cfset CheapAssLine = ''>
  5.     <cfset trimmedLetters = replace(arguments.message," ","","all") />
  6.     <cfset words = listToArray(message, ' ')>
  7.     <cfset letters = structNew()>
  8.     <cfset letterArray = trimmedLetters.toCharArray()>
  9.     <cfloop array="#letterArray#" index="alphabet">
  10.         <cfif not structKeyExists(letters, alphabet)>
  11.             <cfscript>
  12.                 StructInsert(letters, alphabet, '1');
  13.             </cfscript>
  14.         <cfelse>
  15.             <cfset letters[alphabet] = letters[alphabet] + 1>
  16.         </cfif>
  17.     </cfloop>
  18.     <cfset lineFeed = "<br />"&chr(13)&chr(10)>
  19.     <cfset rowcount = 1>
  20.     <cfset CheapAssRows = structNew()>
  21.     <cfloop array="#words#" index="CheapAssWord">
  22.         <cfif (len(CheapAssWord) + len(CheapAssLine)) lte (arguments.width)>
  23.             <cfset CheapAssLine = CheapAssLine & CheapAssWord & ' '>  
  24.             <cfset CheapAssRows['Row ' & rowcount & ':'] = CheapAssLine>
  25.         <cfelse>
  26.             <cfset rowcount++>
  27.             <cfset CheapAssLine = ''>
  28.             <cfset CheapAssLine = CheapAssLine & CheapAssWord & ' '>
  29.             <cfset CheapAssRows['Row ' & rowcount & ':'] = CheapAssLine>
  30.         </cfif>
  31.     </cfloop>
  32.     <cfset JoesSignage = structNew()>
  33.     <cfset JoesSignage.Rows = CheapAssRows>
  34.     <cfset JoesSignage.Letters = letters>
  35.      <cfreturn JoesSignage>
  36. </cffunction>
  37.  
  38.  
  39. <cfif isDefined("form.fieldNames")>
  40.         <cfset JoesSignage = getSignInfo(form.message, form.slots)>
  41.         <cfdump var="#JoesSignage#">
  42. </cfif>
  43.  
  44. <form action="" method="post">
  45.         <label for="message">Message:</label>
  46.         <input name="message" id="message" type="text" value="Jar Jar Sucks Ewoks"/>
  47.         <br/>
  48.  
  49.         <label for="slots">Slots:</label>
  50.         <input name="slots" id="slots" type="text" value="10"/>
  51.         <br/>
  52.  
  53.         <input name="go" type="submit" value="Go"/>
  54. </form>
Advertisement
Add Comment
Please, Sign In to add comment