Split a table into columns with different delimiters

조회 수: 5 (최근 30일)
bigseat
bigseat 2016년 9월 2일
답변: Star Strider 2016년 9월 2일
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!

답변 (1개)

Star Strider
Star Strider 2016년 9월 2일
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'

카테고리

Help CenterFile Exchange에서 Logical에 대해 자세히 알아보기

태그

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by