How to: Convert Roman numerals to Arabic numbers ?
-
I have an Html document that sometimes uses Roman numerals
and I want to Convert Roman numerals to Arabic numbers .
How can I do this ?
Thanks for your Help… -
Notepad++ doesn’t know roman numerals as distinct from any other character, and has no inherent meaning associated. Most of the roman-to-arabic conversions I know use math, and Notepad++ search/replace cannot do math.
You would either have to find or write a plugin that could do it, or use a plugin like PythonScript and write a script that would do the conversion.
When making the plugin or script, just make sure you think about edge cases like
<blockquote>I came, I saw, I conquered</blockquote>(which should not become<blockquote>1 came, 1 saw, 1 conquered</blockquote>), or<p>Use Notepad++, not vi, if you're on Windows</p>(which should not become<p>Use Notepad++, not 6, if you're on Windows</p>) -
I got interested:
# encoding=utf-8 """in response to https://community.notepad-plus-plus.org/topic/21611/ matches any "roman numeral", which I define as * any "word" that's a combination of I, V, X, L, C, D, M (only upper case) * except if it's a lone I at the beginning of a line, or a lone I after a . or ? or ! or ; or , or " and one or two spaces """ from Npp import * def roman_to_int(s): """stolen from https://www.w3resource.com/python-exercises/class-exercises/python-class-exercise-2.php""" rom_val = {'I': 1, 'V': 5, 'X': 10, 'L': 50, 'C': 100, 'D': 500, 'M': 1000} int_val = 0 for i in range(len(s)): if i > 0 and rom_val[s[i]] > rom_val[s[i - 1]]: int_val += rom_val[s[i]] - 2 * rom_val[s[i - 1]] else: int_val += rom_val[s[i]] return int_val def deromanize_match(m): return str(roman_to_int(m.group().rstrip())) editor.beginUndoAction() editor.rereplace(r'(?-is)(?!^\x20*I\x20)(?!(?<=[.?!,;"]\x20)I\x20)(?!(?<=[.?!,;"]\x20\x20)I\x20)\b[IVXLCDM]+\b', deromanize_match) editor.endUndoAction()converts
Convert MMMCMLXXXVI Convert MDCLXVI I say, I am not sure, but treat this line as pronouns Don't edit using the vi editor, which won't match because it's lower case Some sentence. I am still a sentence with a pronoun. But this. The I here is a roman numeral. I say, II is surely roman.to
Convert 3986 Convert 1666 I say, I am not sure, but treat this line as pronouns Don't edit using the vi editor, which won't match because it's lower case Some sentence. I am still a sentence with a pronoun. But this. The 1 here is a roman numeral. I say, 2 is surely roman. -
Whoa!
Thank you very much Peter .
Here is the .html :
[https://vmars.us/ShowMe/A.Little.Book-On-the-Christian-Life-John-Calvin-Direct-Edit.html](link url)
…Vernon
Hello! It looks like you're interested in this conversation, but you don't have an account yet.
Getting fed up of having to scroll through the same posts each visit? When you register for an account, you'll always come back to exactly where you were before, and choose to be notified of new replies (either via email, or push notification). You'll also be able to save bookmarks and upvote posts to show your appreciation to other community members.
With your input, this post could be even better 💗
Register Login