Text Item Delimeter problem... this is probably VERY simple to fix...

Hi all,

I have some text files that are structured as follows:

Page 1
Content Content Content Content Content Content Content Content
Content Content Content Content Content Content Content Content
Content Content Content Content
Page 2
Content Content Content Content Content
Content Content
Content Content Content Content

…and so on

I need to add 2 to each page number, so I wrote a script using TIDs to help me. I prepped the text in word by adding “ª” at the end of each page to be used as the TID.

My script is broken because after each text item beyond the third pass is added, I lose my “ª” symbol. You can see the hack job I did trying to correct this:

set mainText to "Page 1  
FooªPage 122  
BarªPage 555 
GooªPage 6744 
Gaaª"

set AppleScript's text item delimiters to "ª"

set itemcount to count text items of mainText
repeat with i from 1 to itemcount
	set thisItem to text item i of mainText
	--display dialog thisItem
	set originalNumber to word 2 of thisItem as number
	--display dialog originalNumber
	set newNumber to originalNumber + 2
	set T1 to word 1 of thisItem
	set thisItem to {T1 & " " & newNumber & " " & words 3 through end of thisItem & "ª"} as string
	set startText to text item i of mainText
	if i = 1 then
		set mainText to (thisItem & text items (i + 1) through end of mainText)
	else if i = 2 then
		set mainText to (text item 1 of mainText & "ª" & thisItem & text items (i + 1) through end of mainText)
	else if i > 2 then
		set mainText to (text items (i - 1) through beginning of mainText & "ª" & thisItem & text items (i + 1) through end of mainText)
--do I need something in here to add the "ª" back to the end of each text item?
	end if
	display dialog mainText
end repeat

What should I do?

Thanks!

UPDATE: I got it. I had to introduce a new TID to designate everything before thisItem and after, then switch TIDs on the fly to get everything straight. I’ll post the code later to ask for a more elegant solution. Thanks!