Replace Text in Lines

Klaus Major klaus at major-k.de
Tue Jan 9 08:48:24 EST 2007


Hi Michael,

> Hi  all
> I have a numbered text file with 1 to 800 lines, I need to replace  
> text in specific lines with text from a field. I can replace by  
> individual lines with the replace into a single line number, but  
> how is this done with mutliple odd lines ?
>
> replace 12345 with 67890 in the text file in all the listed odd  
> individual line numbers.
>
> example
> 67890-Dataname  < field "replace" contents
>
> set the itemdelimiter to "-"
> put item 1 of fld replace into lines  
> 299,322,345,368,391,414,437,460,483,506 of field "textfile"

Looks like you need a nice repeat loop :-)

...
set the itemdelimiter to "-"
put item 1 of fld replace into text2replace
put fld "textfile" into tTextfile
## Doing everything in memory instead of manipulating the field  
directly will speed up things a LOT!
set itemdel to ","
repeat for each item i in "299,322,345,368,391,414,437,460,483,506"
    put text2replace into line i of tTextfile
end repeat
put tTextfile into fld "textfile"
...

Et voila!

Hope that helps.

> Michael

Regards from germany

Klaus Major
klaus at major-k.de
http://www.major-k.de




More information about the use-livecode mailing list