regex - Selectively deleting commas and splitting strings -
i have s string looks like
txt = '"emb","ishares j,p. morg",110.81,n/a'
i'm using strsplit(txt,',');
break separate strings based on comma delimiter. want ignore comma between 'j'
, 'p'
, since it's not delimiter; it's part of name.
is there way can "if comma between 2 quotes there other characters between quotes, delete comma"?
a silly (but functional) answer:
inquotes=false; keep=true(1,length(txt)); v=1:length(txt) if (txt(v)=='"') inquotes=~inquotes; elseif (txt(v)==',' && inquotes) keep(v)=false; end end txt=txt(keep); tt=strsplit(txt,',');
this will, if in quotes, remove commas can use strsplit. understood want do, correct?
Comments
Post a Comment