Jump to content
Ketarin forum

Array operations


shawn
 Share

Recommended Posts

Per a discussion from here:

http://ketarin.canneverbe.com/forum/viewtopic.php?id=150

 

 

I'd really find it useful to be able to perform mass replacements on a variable by passing in an array of "find" and an array of "replace" values. This would work something like this:

{myvar:arrayreplace:,:Jan,Feb,Mar,Apr,May,Jun,Jul,Aug,Sep,Oct,Nov,Dec:01,02,03,04,05,06,07,08,09,10,11,12}

 

Where "arrayreplace" is the function name, "," is the delimiter, "Jan,Feb,Mar,Apr,May,Jun,Jul,Aug,Sep,Oct,Nov,Dec" is the find array, and "01,02,03,04,05,06,07,08,09,10,11,12" is the replacement array.

{myvar:arrayreplace:delimiter:findarray:replacearray}

 

Pushing that against the following values would yield these respective results:

 

2010-May-08 = 2010-05-08

Dec 11, 2004 = 12 11, 2004

I hate June bugs = I hate 06e bugs

 

Here's another place it would come in handy:

{myvar:arrayreplace:|:, Build| Build | part | beta | b:.|.|.|.|-}

 

This would convert:

Picasa 3.6, Build 3622 = Picasa 3.6.3622

Audacity 1.3 beta 22 = Audacity 1.3.22

MyApp 2.9 b4 = MyApp 2.9-4

Edited by shawn
Link to comment
Share on other sites

  • 2 weeks later...

To my knowledge, regexreplace provides several search strings, but only one *replacement* string. Am I misunderstanding it's operation? I don't see how it could be used to replace the month *name* with it's numeric equivalent in a single operation.

Link to comment
Share on other sites

  • 4 weeks later...
  • 2 months later...

This is going to enable me to SIMPLIFY my template collection!!! Simpler is ALWAYS better!!! :)

 

BTW, for Ketarin users that have not used this added function, it was actually named 'multireplace' and from Shawn's example above it would be:

 

{version:multireplace:|:, Build| Build | part | beta | b:.|.|.|.|-}

 

which is similar to what I am going to use to simplify my version regex scrapes in my template collection. This will allow me to eradicate Beta, Build, spaces, - , commas, _, etc. from app versions in one shot!! YEAH!!

Link to comment
Share on other sites

Just an aside, in most cases in your example:

{version:multireplace:|:, Build| Build | part | beta | b:.|.|.|.|-}

...you'd be better off using this:

{version:regexreplace:[^\d\.]+:.}

That's the most effective means if you KNOW that legitimate version numbers for a job should always include only numbers and dots.

Link to comment
Share on other sites

  • 6 months later...

Is there a way for it to be used as a global variable instead of having to put the function in each app? Maybe I'm doing it wrong but when I try to use it as a global variable I get a 404 error, for example, the app I'm downloading is xmedia-recode.

I get "xmedia recode The remote server returned an error: (404) Not Found. (http://www.xmedia-recode.de/download/XMediaRecode{version:regexreplace:[/.]+:}_setup.exe)" where the expression would be the version number. I hope that makes sense.

Link to comment
Share on other sites

Not as a "global" variable, but you can use it within another variable to rely on the first. Just create a new variable (+), name it (like "newversion"), click "textual content" and then enter your parsing rules, such as:

{version:regexreplace:[/.]+:}

 

This works perfectly, as long as the variable "version" has been defined. It will automatically be parsed first so the new variable ("newversion") can be correctly assigned.

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.