How to compact a string?
1 view (last 30 days)
Show older comments
pamela sulis
on 11 Nov 2015
Commented: pamela sulis
on 11 Nov 2015
Hi! I have a sting 'aaaaaaabccccbbbdcccccaaaa' and I want to trasform it in 'abcbdca': I want to have only one of the consecutive equal value. Can you give me some suggests? Thanks
0 Comments
Accepted Answer
Walter Roberson
on 11 Nov 2015
Edited: Walter Roberson
on 11 Nov 2015
s = 'aaaaaaabccccbbbdcccccaaaa'
new_s = regexprep(s, '(.)(\1)+', '$1');
3 Comments
More Answers (0)
See Also
Categories
Find more on Characters and Strings in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!