I thought I had my roman numeral problem solved, but only with single digits

Hello again,

Sorry to be asking for so much help but I have tired to resolve things myself for hours and still fail. :sob:

Anyhow, I have read many threads on converting Arab to Roman and Roman to Arab, including Converting roman to arabic number and vice versa

From the fields %movement% and %movementtotal% I want to convert Arab numerals to Roman numbers and vice-versa. I create the names of my titles from the work & movement fields (%title% = %work%: %movement%. %movement name%) and would keep everything in roman up to 21 movements (a rule I read somewhere), but I found out that iTunes does not take roman numerals for their respective fields, so if I do not use arabic numbers, the movement number or total do not register.

For converting from roman to arab, I tried the following:
Field: Movement

$replace(%movement%,I,1,II,2,III,3,IV,4,V,5,VI,6,VII,7,VIII,8,IX,9,X,10,XI,11,XII,12,XIII,13,XIV,14,XV,15,XVI,16,XVII,17,XVIII,18,XIX,19,XX,20,XXI,21)

but any number over 9 created problems, because they were made up of the values before (e.g, "11" came back as "II" because it was made up of two "1"s. I could add leading zeros, which would solve the problem, but m4a does not allow leading zeros. I did find I could format the column using $num(%movement%,2), which would theoretically solve the problem of Arab to Roman, albeit not very elegantly, but it would not solve the problem that occurs when converting Roman back to Arab numbers.

When trying the same method to convert Arab numerals to Roman using

$replace(%movementtotal%,1,I,2,II,3,III,4,IV,5,V,6,VI,7,VII,8,VIII,9,IX,10,X,11,XI,12,XII,13,XIII,14,XIV,15,XV,16,XVI,17,XVII,18,XVIII,19,XIX,20,XX,21,XXI)

a value such a "II", will return "11" instead of "2".

There has to be a way to use scripts to either make each value discrete, where 1 and 11 are treated differently. I think it would involve some $iflonger function but I just can't figure it out. :man_facepalming: I have been trying a long time and thought maybe someone with much greater knowledge of Regular Expressions can help.

It would be greatly appreciated!! :clap:

I think that $replace() processes the pairs from the beginning to the end.
So if you start with the longest Roman number and work your way down to the shortest, it should work.
And if nothing helps, split the action into so many further actions, that you end up with unique strings after each process step.

1 Like

Thanks ohrenkino!

Unfortunately the first suggestion did not work, but the second did, though it was time consuming! At least I only have to do the work once. I will post a link to the Actions once I verify everything is working.

Using WORD I was able to replace values in the .mta files to make the creation of an action for each instance: Movement Arab to Roman, Movement Roman to Arab, Movementtotal Arab to Roman, Movementtotal Roman to Arab.

Thanks again for your help. I was going crazy trying to figure this out.

OK, so I got things working and want to share my not-so-elegant scripts. Maybe they will be of use to someone in the future. If I should post them elsewhere so they could easily be found, please let me know. I did not want to put it in the REG Ex thread because it is not a regular expression.

Movement Roman to Arabic.mta (942 Bytes) Movement Total Roman to Arabic.mta (1.0 KB) Movement Arabic to Roman.mta (939 Bytes) Movement Total Arabic to Roman.mta (1.0 KB)