Jump to content

Split a character string based on change of character: Difference between revisions

→‎{{header|ooRexx}}: append =={{header|Pascal}}==
(→‎{{header|ooRexx}}: append =={{header|Pascal}}==)
Line 1,614:
End
Say ol</lang>
{{out}}
<pre>g, HHH, 5, YY, ++, ///, \</pre>
=={{header|Pascal}}==
<lang pascal>program SplitChars;
{$IFDEF FPC}
{$MODE DELPHI}{$COPERATORS ON}
{$ENDIF}
const
TestString = 'gHHH5YY++///\';
 
function SplitAtChars(const S: String):String;
var
i : integer;
lastChar:Char;
begin
result := '';
IF length(s) > 0 then
begin
LastChar := s[1];
result := LastChar;
For i := 2 to length(s) do
begin
if s[i] <> lastChar then
begin
lastChar := s[i];
result += ', ';
end;
result += LastChar;
end;
end;
end;
 
BEGIN
writeln(SplitAtChars(TestString));
end.</lang>
{{out}}
<pre>g, HHH, 5, YY, ++, ///, \</pre>
Anonymous user
Cookies help us deliver our services. By using our services, you agree to our use of cookies.