Split a table into columns with different delimiters

5 visualizaciones (últimos 30 días)
bigseat
bigseat el 2 de Sept. de 2016
Respondida: Star Strider el 2 de Sept. de 2016
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!

Respuestas (1)

Star Strider
Star Strider el 2 de Sept. de 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'

Categorías

Más información sobre Logical en Help Center y File Exchange.

Etiquetas

Community Treasure Hunt

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

Start Hunting!

Translated by