仅在 begin{document} 和 \end{document} 之间替换
Replacement only between begin{document} and \end{document}
我从堆栈溢出中得到了一些代码并且它正在工作,但是当将该代码更改为我的要求时(仅在 begin{document} 和 \end{document} 之间替换)它不起作用
这是我得到的代码
put wordOffset("begin{document}",fld "MytextField") into tBegin
put wordOffset("end{document}",fld "MytextField") into tEnd
put replaceText(word tBegin to tEnd of fld "MytextField","bad","good") into word tBegin to tEnd of fld "MytextField"
我正在使用以下代码。我如何将上面的代码转换为我的要求。
on mouseUp
put the htmlText of field "MytextField" into myHtml
set the caseSensitive to true
put the field SRText into myArrayToBe
split myArrayToBe by CR
put the number of lines of (the keys of myArrayToBe) into myArraylength
repeat with i = 1 to myArraylength
put myArrayToBe[i] into y
split y by colon
put y[1] into searchStr
put y[2] into replaceStr
if searchStr is empty then
put the 0 into m
else
replace searchStr with "<strike><font bgcolor=" & quote & "yellow" & quote & ">" & searchStr & "</font></strike><font bgcolor=" & quote & "green" & quote & ">" & replaceStr & "</font>" in myHtml
end if
end repeat
set the htmlText of fld "MytextField" to myHtml
end mouseUP
现在我想我明白你的问题了,试试这个...
on mouseUp
put the htmlText of field "MytextField" into myHtml
## First we need to break up myHTML into 3 parts so we can edit the "Document" part...
-- Find the document "begin" marker and put it's position into the tBegin variable
put wordOffset("begin{document}",myHtml) into tBegin
-- Find the document "end" marker and put it's position into the tEnd variable
put wordOffset("end{document}",myHtml) into tEnd
put word 1 to tBegin of myHtml into tHeader -- Part 1
put word (tBegin +1) to (tEnd -1) of myHtml into tDocument -- Part 2 = the Document to change
put word tEnd to -1 of myHtml into tFooter -- Part 3
set the caseSensitive to true
put field "SRText" into myArrayToBe
split myArrayToBe by CR
put the number of lines of (the keys of myArrayToBe) into myArraylength
repeat with i = 1 to myArraylength
put myArrayToBe[i] into y
split y by colon
put y[1] into searchStr
put y[2] into replaceStr
if searchStr is empty then
put the 0 into m
else
replace searchStr with "<strike><font bgcolor=" & quote & "yellow" & quote & ">" & searchStr & "</font></strike><font bgcolor=" & quote & "green" & quote & ">" & replaceStr & "</font>" in tDocument
end if
end repeat
## Now we can rebuild the htmlText from the 3 parts and put it back in to the field...
set the htmlText of fld "MytextField" to tHeader && tDocument && tFooter
end mouseUp
我从堆栈溢出中得到了一些代码并且它正在工作,但是当将该代码更改为我的要求时(仅在 begin{document} 和 \end{document} 之间替换)它不起作用
这是我得到的代码
put wordOffset("begin{document}",fld "MytextField") into tBegin
put wordOffset("end{document}",fld "MytextField") into tEnd
put replaceText(word tBegin to tEnd of fld "MytextField","bad","good") into word tBegin to tEnd of fld "MytextField"
我正在使用以下代码。我如何将上面的代码转换为我的要求。
on mouseUp
put the htmlText of field "MytextField" into myHtml
set the caseSensitive to true
put the field SRText into myArrayToBe
split myArrayToBe by CR
put the number of lines of (the keys of myArrayToBe) into myArraylength
repeat with i = 1 to myArraylength
put myArrayToBe[i] into y
split y by colon
put y[1] into searchStr
put y[2] into replaceStr
if searchStr is empty then
put the 0 into m
else
replace searchStr with "<strike><font bgcolor=" & quote & "yellow" & quote & ">" & searchStr & "</font></strike><font bgcolor=" & quote & "green" & quote & ">" & replaceStr & "</font>" in myHtml
end if
end repeat
set the htmlText of fld "MytextField" to myHtml
end mouseUP
现在我想我明白你的问题了,试试这个...
on mouseUp
put the htmlText of field "MytextField" into myHtml
## First we need to break up myHTML into 3 parts so we can edit the "Document" part...
-- Find the document "begin" marker and put it's position into the tBegin variable
put wordOffset("begin{document}",myHtml) into tBegin
-- Find the document "end" marker and put it's position into the tEnd variable
put wordOffset("end{document}",myHtml) into tEnd
put word 1 to tBegin of myHtml into tHeader -- Part 1
put word (tBegin +1) to (tEnd -1) of myHtml into tDocument -- Part 2 = the Document to change
put word tEnd to -1 of myHtml into tFooter -- Part 3
set the caseSensitive to true
put field "SRText" into myArrayToBe
split myArrayToBe by CR
put the number of lines of (the keys of myArrayToBe) into myArraylength
repeat with i = 1 to myArraylength
put myArrayToBe[i] into y
split y by colon
put y[1] into searchStr
put y[2] into replaceStr
if searchStr is empty then
put the 0 into m
else
replace searchStr with "<strike><font bgcolor=" & quote & "yellow" & quote & ">" & searchStr & "</font></strike><font bgcolor=" & quote & "green" & quote & ">" & replaceStr & "</font>" in tDocument
end if
end repeat
## Now we can rebuild the htmlText from the 3 parts and put it back in to the field...
set the htmlText of fld "MytextField" to tHeader && tDocument && tFooter
end mouseUp