Split a table into columns with different delimiters
조회 수: 5 (최근 30일)
이전 댓글 표시
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
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'
댓글 수: 0
참고 항목
카테고리
Help Center 및 File Exchange에서 Logical에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!