Modify text in a column
9 次查看(过去 30 天)
显示 更早的评论
Dear all, I want to modify just the first column of a file, removing the letters and keeping the numbers. The columns contain string like d200n-h. How it is possible?
Thanks,
Marco
0 个评论
回答(1 个)
Walter Roberson
2019-6-26
编辑:Walter Roberson
2019-6-26
Assuming comma delimited:
S = fileread('YourFile.txt');
newS = regexprep(S, '^\D*(\d+)[^,]+(,.*$)', '$1$2', 'lineanchors', 'dotexceptnewline');
fid = fopen('YourNewFile.txt');
fwrite(fid, newS);
fclose(fid)
This should work even if there is "" around the string, but it will remove the "" if present.
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Creating, Deleting, and Querying Graphics Objects 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!