Run-length encoding: Difference between revisions

Content added Content deleted
m (→‎{{header|REXX}}: added wording to the REXX section header.)
Line 2,166: Line 2,166:


integer, parameter :: bufsize = 100 ! Sets maximum size of coded and decoded strings, adjust as necessary
integer, parameter :: bufsize = 100 ! Sets maximum size of coded and decoded strings, adjust as necessary
character(bufsize) :: teststr = "WWWWWWWWWWWWBWWWWWWWWWWWWBBBWWWWWWWWWWWWWWWWWWWWWWWWBWWWWWWWWWWWWWW"
character(bufsize) :: teststr = "WWWWWWWWWWWWBWWWWWWWWWWWWBBBWWWWWWWWWWWWWWWWWWWWWWWWBWWWWWWWWWWWWWW"
character(bufsize) :: codedstr = "" Encode (Data (Index..Data'Last));
character(bufsize) :: codedstr = "", decodedstr = ""
end;
end;
end if;
end Encode;
function Decode (Data : String) return String is
begin
if Data'Length = 0 then
return "";
else
declare
Index : Integer := Data'First;
Count : Natural := 0;
begin
while Index , decodedstr = ""
call Encode(teststr, codedstr)
call Encode(teststr, codedstr)
Line 2,235: Line 2,221:
end subroutine
end subroutine
end program</lang>
end program</lang>

Output:
<pre>
12W1B12W3B24W1B14W
WWWWWWWWWWWWBWWWWWWWWWWWWBBBWWWWWWWWWWWWWWWWWWWWWWWWBWWWWWWWWWWWWWW
</pre>


=={{header|FreeBASIC}}==
=={{header|FreeBASIC}}==