Anonymous user
Split a character string based on change of character: Difference between revisions
Split a character string based on change of character (view source)
Revision as of 08:41, 14 October 2021
, 2 years ago→{{header|ooRexx}}: append =={{header|Pascal}}==
m (→JS ES6) |
(→{{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>
|