char replacement


[ Zettels Traum ] [ search / suche ]


Here's a little utility script for taking an input string and replacing
all occurences of one char with another (I needed to create unix file
names from framelabels and wanted to put "_" into all blank chars).

on replaceChar str, oldChar, newChar
  -- replaces all occurences of oldChar in str with newChar
  -- ok for use in small input, it would be slow for large text

  repeat while str contains oldChar
    put newChar into char (offset (oldChar, str)) of str
  end repeat
  return str
end

i.e.

  put replaceChar("alan is the worst lingo coder ever", " ",  "_")
  -- "alan_is_the_worst_lingo_coder_ever"

It can remove all occurences:

  put replaceChar("alan is the worst lingo coder ever", " ",  "")
  -- "alanistheworstlingocoderever"

as well as inserting words

  put replaceChar("alan is the worst lingo coder ever", " ",  "")
  -- "alanistheworstlingocoderever"

--
alan   levine





Dazu:























D. Plänitz