Replacing text within tags

Hello all,
AppleScript Newbie, so please be gentle.
I want of set up a psuedo style sheet (not CSS) when using TextEdit. For instance, I’d llike to mark headers with

,

etc. tags, and when the form is done, simply run an Applescript, that’ll look for text between

, change the font and size, to a pre-set font in the script, and finally remove the no longer needed

tags.
I seem to have most figured out, but cannot figure out how to instruct Applescript to look for text with the tags. (Also well as the part about going back and removing the tags.
I’m not looking for anyone to write this for me, but maybe a quick example on find and replace using AS.
Thanks, Fernando
P.S. Please, no suggestions about using Word or AppleWorks or another commercial product, to set style to a document…I don’t have those products and can not afford them, either. I’m hoping to use this as a poor man’s substitute. --Thanks

Hey all,
Thanks for the responses. Sorry about placing HTML tags in the message. I didn’t realize that would happen.
I think I need to clarify what application I’m referring to. I do not mean the shareware Text-Edit +. I’m referring to the text editor that comes with OS X. Also, the suggestions given seem to suggest that I use applications find and replace, which of course is an obvious route, but I’d like to create an automated method using AppleScript…Possibly even fine tuning it to be an droplet.
Thanks again, everyone.
Fernando

Fernando, absolutely no need to apologize - most of us here have done far worse than that at times (well, I have). Anyway you’ve started off something quite interesting…
Kel, how do you do that without replacing the text? (i.e. just altering the style of the existing text between the tags). I can see how to do it with a lot of code, so what I mean really is how do you do it with just a few words?
Marc’s code works perfectly, of course, but your modification could/would make it significantly faster.
Andreas

Hi Andreas,
What I came up with searches, then gets the text from the selection. Then, change the style of the selection and sets the selection to the text. One search seems to be faster than two searches. Here it is:

   property tag_list : {"", ""} 
--set start_ticks to the ticks 
set {tag_1, tag_2} to tag_list 
set {length_1, length_2} to {count tag_1, count tag_2} 
set the_string to tag_1 & "^*" & tag_2 
tell application "Tex-Edit Plus" 
 activate 
 tell front window 
  select insertion point before contents 
  ---------- repeat? 
  set found_flag to true 
  repeat while found_flag 
   set found_flag to (search contents looking for the_string finding ¬ 
    next with searching from cursor) 
   set style of selection to {bold, italic} 
   set mid_text to ¬ 
    (characters (length_1 + 1) thru -(length_2 + 1) of selection) 
   set selection to mid_text as string 
  end repeat 
  ---------- 
 end tell 
end tell 
--set end_ticks to the ticks 
--set the_diff to end_ticks - start_ticks 
--display dialog the_diff 

If you want to compare the times and you have Jon’s Commands then uncomment the ticks part. Not sure if this is a true measure though. Also, the Event Log was open when testing it in the Script Editor and maybe the script with more output may be slowed by this but I don’t know. I tried it the other way with two searches and this way was almost twice as fast.
Later, kel.

Come to think of it, it’s faster with ‘replace’ than ‘repeat’:

   property tag_list : {"", ""} 
--set start_ticks to the ticks 
set {tag_1, tag_2} to tag_list 
set {length_1, length_2} to {count tag_1, count tag_2} 
set the_string to tag_1 & "^*" & tag_2 
tell application "Tex-Edit Plus" 
 activate 
 tell front window 
  select insertion point before contents 
  search contents looking for the_string finding ¬ 
   next with searching from cursor 
  set mid_text to ¬ 
   (characters (length_1 + 1) thru -(length_2 + 1) of selection) as string 
  replace contents looking for the_string replacing with ¬ 
   mid_text replacing with styles {style:{bold, italic}} 
 end tell 
end tell 
--set end_ticks to the ticks 
--set the_diff to end_ticks - start_ticks 
--display dialog the_diff  

Fascinating, Kel. While you were doing that I got to:

set {tag1, tag2} to {"", ""}
set txt to "Plain Jane and " & tag1 & "her chubby companion" & tag2 & " got bored."

tell application "Tex-Edit Plus"
    activate
    if number of windows = 0 then make new window
    tell front window
        set {style of contents, contents} to {plain, txt}
        say "Thats the  text, now weel play [[pbas +1]]tag."
        search looking for tag1 & "^*" & tag2
        set x to selection
        replace looking for x replacing with 
            (text ((tag1's length) + 1) thru -((tag2's length) + 1) of x) 
                replacing with styles {style:bold, color:red}
        select last insertion point
    end tell
end tell

…which I didn’t like at all with its ‘length of tags’. But now I see that you used that as well - so I feel better! …In fact, the similarities of our two versions I think are quite uncanny. I need a bit of time to look at the differences.
Personally I don’t think the absolute time here matters that much - for me it’s more a question of whether it looks fast enough on the screen - and that it looks ‘clean’. This method seems to satisfy both. Thank you - you’ve given me something to work on.
BTW I did try messing with the actual code inserted by Tex-Edit but it contains (I think) non-printing characters and after bombing out twice I gave up. It would, of course, be nice never to see the tags on screen but I think that’s pie-in-the-sky.
Andreas

Hi Andreas,
The similarity is amazing! I like your user friendly touch to this problem. Getting the wild run more easily has been on my mind also. Maybe someone can come up with some magic.
Later, Kel.

Maybe someone can come up with some Magic. ??
Andreas
just doodling, just doodling,
just doodling…