AutoIt
; ================================= entferne alle Leer- und Kommentarzeilen und poste diesen Code-Block im Thread ==================================
Func _IntegerToRoman($sInteger)
Local $Return
Local Static $M[], $K
If Not UBound($M) Then
$M[1] = 'I'
$M[5] = 'V'
$M[10] = 'X'
$M[50] = 'L'
$M[100] = 'C'
$M[500] = 'D'
$M[1000] = 'M'
$K = MapKeys($M)
EndIf
For $r = UBound($K) - 1 To 0 Step -1
While $sInteger >= $K[$r]
$Return &= $M[$K[$r]]
$sInteger -= $K[$r]
WEnd
Next
$Return = StringReplace($Return, 'IIII', 'IV')
$Return = StringReplace($Return, 'VIV' , 'IX')
$Return = StringReplace($Return, 'XXXX', 'XL')
$Return = StringReplace($Return, 'LXL' , 'XC')
$Return = StringReplace($Return, 'CCCC', 'CD')
$Return = StringReplace($Return, 'DCD' , 'CM')
Return $Return
EndFunc ;==>_IntegerToRoman
Func _RomanToInteger($sRoman)
Local $Return
Local Static $M[], $K
If Not UBound($M) Then
$M['I'] = 1
$M['V'] = 5
$M['X'] = 10
$M['L'] = 50
$M['C'] = 100
$M['D'] = 500
$M['M'] = 1000
$K = MapKeys($M)
EndIf
$sRoman = StringReplace($sRoman, 'CM', 'DCD', 0, 1)
$sRoman = StringReplace($sRoman, 'CD', 'CCCC', 0, 1)
$sRoman = StringReplace($sRoman, 'XC', 'LXL', 0, 1)
$sRoman = StringReplace($sRoman, 'XL', 'XXXX', 0, 1)
$sRoman = StringReplace($sRoman, 'IX', 'VIV', 0, 1)
$sRoman = StringReplace($sRoman, 'IV', 'IIII', 0, 1)
For $c In StringSplit($sRoman, '', 2)
$Return += $M[$c]
Next
Return $Return
EndFunc ;==>_RomanToInteger
; Bonus-Aufgabe für Ambitionierte ;-)
Func _DateToRoman($sDate) ;Input date in the format "YYYY/MM/DD[ HH:MM:SS]", Output in same date-format with roman sign
;If Not StringInStr($sDate, ' ', 0, 1) Then Return '' ; Das hier ist ein Joke. Natürlich muss diese Zeile weg :)
Local $Return, $aDate = StringSplit(StringReplace(StringReplace($sDate, ' ', ':', 0, 1), '/', ':', 0, 1), ':', 2)
For $i = 0 To UBound($aDate) - 1 Step 1
$Return &= _IntegerToRoman($aDate[$i]) & ($i < UBound($aDate) - 1 ? ($i < 2 ? '/' : $i = 2 ? ' ' : ':') : '')
Next
Return $Return
EndFunc ;==>_DateToRoman
; ================================= entferne alle Leer- und Kommentarzeilen und poste diesen Code-Block im Thread ==================================
Alles anzeigen