Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Func boom($str)
- If StringLeft($str, 1) = ":" Then
- $str = StringTrimLeft($str, 1)
- EndIf
- If StringRight($str, 1) = ":" Then
- $str = StringTrimRight($str, 1)
- EndIf
- Local $aSplit = StringSplit($str, ":", $STR_NOCOUNT)
- Local $rtn = ""
- For $i = 0 To UBound($aSplit) - 1 ; Loop through all the elements
- If Not $aSplit[$i] = "" Then ; If not a shortened element
- $rtn &= StringPadLeft($aSplit[$i], 4, "0")
- Else ; It is a shortened element
- For $j = 0 To 8 - UBound($aSplit) ; Append 0000 for yes times
- $rtn &= "0000"
- If $j < 8 - UBound($aSplit) Then ; Append : if not last iteration
- $rtn &= ":"
- EndIf
- Next
- EndIf
- If $i < UBound($aSplit) - 1 Then ; Append : if not last iteration
- $rtn &= ":"
- EndIf
- Next
- Return $rtn
- EndFunc
- Func StringPadLeft($str, $digit, $pad)
- Local $rtn = ""
- For $i = 1 To $digit - StringLen($str)
- $rtn &= $pad
- Next
- $rtn &= $str
- Return $rtn
- EndFunc
- ConsoleWrite(boom("1234:0:2d::") & @CRLF)
- ConsoleWrite(boom("::123:12:0:bc") & @CRLF)
- ConsoleWrite(boom("::") & @CRLF)
- ConsoleWrite(boom(":") & @CRLF)
- ConsoleWrite(boom("2::1") & @CRLF)
- ConsoleWrite(boom("::1") & @CRLF)
- ConsoleWrite(boom("1234:0000:002d:0000:0000:0000:0000:0000") & @CRLF)
- ConsoleWrite(boom("b3c::2:0:10:11") & @CRLF)
- ConsoleWrite(boom("2001:db8:0:0:1:0:0:1") & @CRLF)
- ConsoleWrite(boom("2001:0db8:0:0:1:0:0:1") & @CRLF)
- ConsoleWrite(boom("2001:db8::1:0:0:1") & @CRLF)
- ConsoleWrite(boom("2001:db8::0:1:0:0:1") & @CRLF)
- ConsoleWrite(boom("2001:0db8::1:0:0:1") & @CRLF)
- ConsoleWrite(boom("2001:db8:0:0:1::1") & @CRLF)
- ConsoleWrite(boom("2001:db8:0000:0:1::1") & @CRLF)
- ConsoleWrite(boom("2001:DB8:0:0:1::1") & @CRLF)
Add Comment
Please, Sign In to add comment