55 lines
1.1 KiB
Plaintext
55 lines
1.1 KiB
Plaintext
Dim As String initial, encoded, decoded
|
|
|
|
Function RLDecode(i As String) As String
|
|
Dim As Long Loop0
|
|
dim as string rCount, outP, m
|
|
|
|
For Loop0 = 1 To Len(i)
|
|
m = Mid(i, Loop0, 1)
|
|
Select Case m
|
|
Case "0" To "9"
|
|
rCount += m
|
|
Case Else
|
|
If Len(rCount) Then
|
|
outP += String(Val(rCount), m)
|
|
rCount = ""
|
|
Else
|
|
outP += m
|
|
End If
|
|
End Select
|
|
Next
|
|
RLDecode = outP
|
|
End Function
|
|
|
|
Function RLEncode(i As String) As String
|
|
Dim As String tmp1, tmp2, outP
|
|
Dim As Long Loop0, rCount
|
|
|
|
tmp1 = Mid(i, 1, 1)
|
|
tmp2 = tmp1
|
|
rCount = 1
|
|
|
|
For Loop0 = 2 To Len(i)
|
|
tmp1 = Mid(i, Loop0, 1)
|
|
If tmp1 <> tmp2 Then
|
|
outP += Ltrim(Rtrim(Str(rCount))) + tmp2
|
|
tmp2 = tmp1
|
|
rCount = 1
|
|
Else
|
|
rCount += 1
|
|
End If
|
|
Next
|
|
|
|
outP += Ltrim(Rtrim(Str(rCount)))
|
|
outP += tmp2
|
|
RLEncode = outP
|
|
End Function
|
|
|
|
Input "Type something: ", initial
|
|
encoded = RLEncode(initial)
|
|
decoded = RLDecode(encoded)
|
|
Print initial
|
|
Print encoded
|
|
Print decoded
|
|
End
|