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 20:13, 22 August 2017
, 6 years ago→{{header|Lua}}: Simply scan difference in reverse order and insert delimiter in place
m (→{{header|Lua}}: Simply scan difference in reverse order and insert delimiter in place) |
|||
Line 697:
{{out}}
<pre>g, HHH, 5, YY, ++, ///, \</pre>
'''Alternative:'''
Simply scan difference in reverse order and insert delimiter in place, the loop counter i will not update with length of s.
<lang lua>function splitdiff(s)
for i=#s,2,-1 do
if s:sub(i,i)~=s:sub(i-1,i-1) then
s = s:sub(1,i-1)..', '.. s:sub(i,-1)
end
end
return s
end</lang>
=={{header|Mathematica}}==
|