Re: Simple text question
Re: Simple text question
- Subject: Re: Simple text question
- From: Jon Pugh <email@hidden>
- Date: Mon, 7 Jul 2008 13:00:38 -0700
At 1:03 PM -0400 7/7/08, Script2 wrote:
>6000[F]this is test (#1).
>
>6001[F]this is test (#2).
I'd like to take this opportunity to plug/mention my SmartString class.
http://www.seanet.com/~jonpugh/software/SmartString.applescript
Using this, it's trivial to take apart strings like this.
tell SmartString
setString("6001[F]this is test (#2).") -- you'll use a loop or something
beforeString("[") -- returns 6001
betweenStrings("[", "]") -- returns "F"
betweenStrings("]", "(") -- returns "this is test "
betweenStrings("(", ")") -- returns "#2"'
-- you can also munge the string
keepAfter("]") -- string is now "this is test (#2)."
keepBefore("(") -- string is now "this is test "
end SmartString
from the documentation comments in SmartString:
SmartString 1.6.1 is an AppleScript script object which knows how to perform numerous operations on strings. The complete list of operations are:
newString(aString) --> script object factory method
getString() --> string (only reads)
setString(aString)
setList(aList, seperator)
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)
-- need:
-- getTokenRange(start, end, delim) -> list (only reads)
-- keepTokenRange(start, end, delim)
-- deleteTokensAfter(item, delim)
-- keepTokensAfter(item, delim)
firstToken(delim) --> string (only reads)
deleteFirstToken(delim)
keepFirstToken(delim)
lastToken(delim) --> string (only reads)
deleteLastToken(delim)
keepLastToken(delim)
NthToken(n, delim) --> string (only reads)
deleteNthToken(n, delim)
keepNthToken(n, delim)
trimWhitespace()
uppercase()
lowercase()
For any string parsing in AppleScript, this makes it really simple.
Jon
_______________________________________________
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