Split a table into columns with different delimiters
5 views (last 30 days)
Show older comments
I used textscan to split a table into columns. But i need to use different delimiters for different places. For example:
str = '1,2,3,(one,5),(two,6,co)'
and i want it to be split as
{1},{2},{3},{(one,5)},{(two,6,co)}
The problem is the last two elements contain commas. If i use textscan, these commas in parenthesis will be counted as well. Any help is appreciated!
Answers (1)
Star Strider
on 2 Sep 2016
This isn’t exactly what you asked for, but it’s close:
str='1,2,3,(one,5),(two,6,co)';
out1 = regexp(str, '\(|\)', 'split');
out2 = regexp(out1{1}, ',', 'split');
out = {out2{1:end-1} out1{[2 end-1]}}
out =
'1' '2' '3' 'one,5' 'two,6,co'
0 Comments
See Also
Categories
Find more on Logical 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!