如何使用textread读取包含逗号和at符号的字符串? [英] How to read a string containing a comma and an at sign with textread?
本文介绍了如何使用textread读取包含逗号和at符号的字符串?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我的原型数据行如下:
(1) 11 July England 0-0 Uruguay @ Wembley Stadium, London
当前我正在使用此
[no,dd,mm,t1,p1,p2,t2,loc]=textread('1966.txt','(%d) %d %s %s %d-%d %s @ %[%s \n]');
但这给了我以下错误:
Error using dataread
Trouble reading string from file (row 1, field 12) ==> Wembley Stadium, London\n
Error in textread (line 174)
[varargout{1:nlhs}]=dataread('file',varargin{:}); %#ok<REMFF1>
因此,读取包含逗号的字符串似乎有麻烦,或者是at符号引起了麻烦.我已经仔细阅读了文档,但是在使用@等特殊字符时,或者即使您不想读取包含定界符的字符串,即使我不希望将其识别为定界符,它也没有提及该怎么做.
So it seems to have trouble with reading a string that contains a comma, or it's the at sign that causes trouble. I read the documentation thoroughly but nowhere does it mention what to do when you have special characters such as @ or if you want to read a string that contains a delimiter even though it I don't want it recognized as a delimiter.
推荐答案
您想要的
[no,dd,mm,t1,p1,p2,t2,loc] = ...
textread('1966.txt','(%d) %d %s %s %d-%d %s @ %[^\n]');
这篇关于如何使用textread读取包含逗号和at符号的字符串?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文