Renaming roman folio jobs in numeric folio ?

Post Reply
tsellem
Newbie
Posts: 8
Joined: Thu Feb 02, 2012 6:11 pm

Renaming roman folio jobs in numeric folio ?

Post by tsellem »

Hello,



I'm looking for a function or syntax or regular expression in Powerswitch (09 or 10) to rename jobs with roman number into arabic/numeric number : for example jobs like job_00I job_0II job_III job_0IV to job_001 job_002 job_003 job_004.



If anyone have a good idea or a way to solve my problem, I would appreciate.



Many Thanks.



Thierry.

tsellem@nouvelobs.com
dkelly
TOP CONTRIBUTOR
Posts: 658
Joined: Mon Nov 29, 2010 8:45 pm
Location: Alpharetta GA USA
Contact:

Renaming roman folio jobs in numeric folio ?

Post by dkelly »

The function below will convert Roman numbers to Arabic.



function toarabic( num : String )

{

var vals = { 'I':1, 'V':5, 'X':10, 'L':50, 'C':100, 'D':500, 'M':1000 };

num = num.toUpperCase().replace( /[^IVXLCDM]/g, '' ).replace( /VV/g, 'X' ).replace( /LL/g, 'C' ).replace( /DD/g, 'M' );

var bits = [], i = 0, j = 0, k, l, n = num.length, last = 9999, rep = 0, sum = 0, valid = 1;

for ( ; i < n; i++ ) {

if ( !( bits[j] = vals[ num.charAt(i) ] ) ) {

valid = 0; break;

}

if (j > 0) {

k = bits[j];

l = bits[j - 1];

if( k === (l * 5) || k === (l * 10) ) {

bits[--j] = k - l;

}

}

j++;

}

if ( valid ) {

for ( i = 0; i < j; i++ ) {

k = bits;

sum += k;

if( (last < k) || (rep > 1 && last == k) ||

(last == k && k != 1 && k != 10 && k != 100 && k != 1000) ||

last == k * 4 || last == k * 9 || last * 4 == k * 9 || last * 5 == k * 9 ) {

valid = 0; break;

}

rep = (last == k) ? rep + 1 : 0;

last = k;

}

}

return sum;

}



Dwight Kelly

Apago, Inc.

dkelly@apago.com
tsellem
Newbie
Posts: 8
Joined: Thu Feb 02, 2012 6:11 pm

Renaming roman folio jobs in numeric folio ?

Post by tsellem »

Many Thanks Dwight.



I will try to execute this nice function in Powerswitch.

I don't known where, but I will find and keep you in touch for results.



Many Thanks once again.



Thierry.
Post Reply