repeat loop and formatting question

Robert Brenstein rjb at robelko.com
Mon Nov 17 11:41:10 EST 2008


>Actually, you can type less by eliminating the <font> tags:
>
>put fld 1 into tText
>replace "ck" with "<b>ck</b>" in tText
>replace "ch" with "<b>ch</b>" in tText
>replace "oa" with "<u>ch</u>" in tText
>replace "oo" with "<u>oo</u>" in tText
>

Or in a more generic way -- more code but easier to maintain

put fld 1 into tText
set the caseSensitive to true
put "ck ch" into vChunksToBold
repeat for each word w in vChunksToBold
   replace w with "<b>" & w & "</b>" in tText
end repeat
put "ch oo" into vChunksToUnderline
repeat for each word w in vChunksToUnderline
   replace w with "<u>" & w & "</u>" in tText
end repeat
set the caseSensitive to false
put tText into fld 1

And if think you may need more style in the future, even more generic 
way would be to use an array

put fld 1 into tText
set the caseSensitive to true
put "ck ch" into vChunksToMark["b"] --  bolds
put "ch oo" into vChunksToMark["u"] --  underlines
repeat for each line k in the keys of vChunksToMark
   put "<" & k & ">" into vMarkBeg
   put "</" & k & ">" into vMarkEnd
   repeat for each word w in vChunksToMark[k]
     replace w with vMarkBeg & w & vMarkEnd in tText
   end repeat
end repeat
set the caseSensitive to false
put tText into fld 1

Robert



More information about the use-livecode mailing list