Re: cutting multiple sections from a string?
Re: cutting multiple sections from a string?
- Subject: Re: cutting multiple sections from a string?
- From: Jon Pugh <email@hidden>
- Date: Mon, 02 Sep 2013 23:25:14 -0700
On Sep 2, 2013, at 9:33 PM, Alex Hall wrote:
> Hi all,
> I have a problem and I can't figure out a good way to solve it. Basically, I need to cut multiple sets of characters from a single string, and return the string with all those characters removed. For instance, I might need to take out characters 2 through 5, 10 through 18, and 32 through 33. My problem is that when I make one change, I can't figure out how to save the result and then continue to work on it, since the character offsets are changed (removing three characters moves the offsets of the characters not yet removed).
>
> For reference, the larger problem this function is solving is if statements in templates. I already have a system where the dollar sign precedes keywords which my script replaces with values, such as:
> You are connected to $ssid at $signalStrength dvm.
> What I want to do is add if statements, which are surrounded by ${ and $}. I borrow the trinary operator syntax from Javascript and other languages, using $? and $:, like so:
> ${$wifiConnected$?You are connected to $ssid.$:Wifi is disabled.$}
> Now, the template is smart enough to respond properly whether or not wifi is on.
I’d also like to point out that my SmartString class makes stuff like this a lot simpler.
tell SmartString
setString("${$wifiConnected$?You are connected to $ssid.$:Wifi is disabled.$}")
keepBetween("${", "$}")
replaceStrings("$ssid", "FBI VAN")
set condition to betweenStrings("$", "$?")
set trueString to betweenStrings("$?", "$:")
set falseString to afterString("$:")
end tell
{condition, trueString, falseString}
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