Error "std::exception" with function textscan in Matlab 2013b

2 views (last 30 days)
Hi everybody, i have a file Text.txt with following sepecified content:
!typ truck,bus,car,motor,bicycle
!end typ
!allowed car,motor,bicycle
!end allowed
I want to get the string "car,motor,bicycle" from the row "!allowed car,motor,bicycle". So I did these in MATLAB 2012b:
io_contents = fullfile( 'Text.txt'); % open Textfile
Text = fileread( io_contents ); % read the content of io_contents
Rowbegin = strfind(Text,'!allowed'); find the beginn of the row in Text
Rowend = strfind(Text,'!end allowed')-3 ; find the end of the row in Text
Row = Text(Rowbegin:Rowend)
String = textscan(Row,'!allowed%s ');
String = String{1}{1}
it should work in Matlab 2012b,but in matlab 2013b it shows this message:
Caught "std::exception" Exception message is: invalid string position
at line 6 , where textscan used is.
Could you tell me the reason, and how could I solve it. Is the an alternativ functioini for the function textscan ? Thanks a lot

Answers (1)

Walter Roberson
Walter Roberson on 1 Jan 2014
It would make more sense to use regexp() for that purpose.
String = regexp(Row, '(?:^!allowed\s+)\S+', 'match');

Products

Community Treasure Hunt

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

Start Hunting!