代码供参考
function strOut = decode(str)
i = 0;
while (i<length(str))
i=i+1;
str(i)
if(str(i)<'0' || str(i)>'9')
continue;
end
j = str(i-1);
jp = i-1;
count = 0;
num = 0;
while(i<=length(str) && str(i)>='0' && str(i)<='9')
count = count + 1;
num = (str2double(str(i))) + 10*num;
i = i + 1;
end
repstr = repmat(j, [1,num]);
str = [str(1:jp-1), repstr, str(jp+count+1:end)];
i = i + num-count-1;
end
strOut = str;
end
示例:
decode('g2l4og4')
结果:
ans =
'ggllllogggg'