Re: FindReplace by list
Re: FindReplace by list
- Subject: Re: FindReplace by list
- From: Emmanuel LEVY <email@hidden>
- Date: Sat, 4 Dec 2010 21:26:20 +0100
In case it helps, if you can install Satimage osax, good news, you do
it a one-liner:
change {"word1", "word2", "word3"} into {"1drow", "2drow", 3drow"} in
theFile
and it's as fast as C can be.
"change" supports all flavors of regular expressions.
Emmanuel
Satimage-software
On Dec 4, 2010, at 8:25 PM, Jon Pugh wrote:
At 12:26 PM +0100 12/4/10, Michel Raj wrote:
I'm looking for hints to make a multiple search replace on text
docs (.doc or .rtf)
This is something my SmartString class does easily in pure
AppleScript.
-- sample script
property ss : load script alias
"YourDisk:Folder1:Folder2:SmartString.scpt"
-- read the file
set theText to read file "Your:file:path"
set wordsToReplace to {"word1", "word2", "word3"}
set wordsToSubstitute to {"1drow", "2drow", 3drow"}
tell ss's SmartString
setString(theText)
repeat with i from 1 to number of items of wordsToReplace
replaceStrings(item i of wordsToReplace, item i of
wordsToSubstitute)
end repeat
set theText to getString()
end tell
-- save the file
write theText to file "Your:file:path:"
-- end sample script
SmartString does much more too, and all in pure AppleScript (well,
at some point it uses the "offset" scripting addition which is built
in). It really makes string handling simple though.
getString() --> string (only reads)
setString(aString) --> string
setList(aList, seperator) --> string
on convertListToString(aList, delim) --> string (only reads)
subString(x, y) --> string (only reads)
beforeString(subString) --> string (only reads)
afterString(subString) --> string (only reads)
betweenStrings(afterThis, beforeThis) --> string (only reads)
appendString(aString) --> string
prependString(aString) --> string
insertBefore(subString, thisString) --> string
insertAfter(subString, thisString) --> string
deleteCharacters(x, y) --> string
deleteString(subString) --> string
deleteBefore(beforeString) --> string
deleteAfter(afterString) --> string
deleteBetween(beforeThis, afterThis) --> string
keepBefore(beforeString) --> string
keepAfter(afterString) --> string
keepBetween(beforeThis, afterThis) --> string
replaceString(subString, withString) --> string
replaceStrings(subString, withString) --> string
replaceBetween(frontTag, rearTag, newValue) --> string
getTokens(delim) --> list (only reads)
setTokens(aList, delim) --> string
beforeToken(token, delim) --> string (only reads)
afterToken(token, delim) --> string (only reads)
getTokenRange(startIndex, endIndex, delim) --> list (only reads)
deleteTokenRange(startIndex, endIndex, delim) --> string
keepTokenRange(startIndex, endIndex, delim) --> string
deleteTokensAfter(token, delim) --> string
keepTokensAfter(token, delim) --> string
firstToken(delim) --> string (only reads)
deleteFirstToken(delim) --> string
keepFirstToken(delim) --> string
lastToken(delim) --> string (only reads)
deleteLastToken(delim) --> string
keepLastToken(delim) --> string
NthToken(n, delim) --> string (only reads)
deleteNthToken(n, delim) --> string
keepNthToken(n, delim) --> string
trimWhitespace() --> string
uppercase() --> string
lowercase() --> string
SmartString is available on my web site in source format:
http://www.seanet.com/~jonpugh/software/SmartString.applescript
Jon
_______________________________________________
Do not post admin requests to the list. They will be ignored.
AppleScript-Users mailing list (applescript-
email@hidden)
Help/Unsubscribe/Update your Subscription:
Archives: http://lists.apple.com/archives/applescript-users
This email sent to email@hidden
_______________________________________________
Do not post admin requests to the list. They will be ignored.
AppleScript-Users mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
Archives: http://lists.apple.com/archives/applescript-users
This email sent to email@hidden