convert string into a table of letters

 say you have a few words in a sentence or a bunch of words in a line (could be a very long line - I think this requires there to be no "returns" or "new lines" to work). Say you wanted to create a table of all the letters and spaces. This is one way to achieve it.

Eg. Here are some words in a line. This might be displayed as a few lines because there are so many words, but there is no return or new line character.

  • Your words will sit inside a text DAT, or some form of DAT. Lets say it's in a select DAT called "select1"
  • Attach a Substitute DAT
  • In the before parameter field, toggle the python option and enter: op('select1').text
  • In the after field, enter : op('select1').text.replace("","/")[1:-1]
  • The first bit of code is just taking your original text.
  • The second is specifying what to replace, in our case it is putting a "/" after everything. The part in the square brackets is saying to start at the 1th letter and stop at the -1th (eg, 1 after the start and 1 before the end).
  • The resultant text would be something like - H/e/r/e/ /a/r/e/ /s/o/m/e/ /w/o....... etc.
  • Next attach a Convert DAT, set the "how" to Table
  • and set the "split cells at" to /
  • So first we've added the / after each character & space, then we split it using the /.
  • The table created will be a horizontal one - one row, many columns - it is likely that we want to have a table that is vertical - one column, many rows! For this we use the Transpose DAT
  • We finally have the vertical table, with one letter (or space) in each cell!

Comments

Popular posts from this blog

Rollover effect, panel chop, image selector, containers, dat execute, panel execute, strings, ifs, renderpick and instances