Selectively removing comma delimiters in a text file
Mostrar comentarios más antiguos
Hi,
I'm looking to remove commas that only appear after a number and before a tab delimiter from a text file.
I cannot provide the text file, as this is for a school project and doing so would most likely flag my submission. Also, I'm not looking for my code to be corrected, but rather an explanation as to how some commands behave and could be applied, as well as any guiding thoughts you may have.
https://www.mathworks.com/matlabcentral/answers/93033-how-can-i-find-and-replace-tab-or-space-characters shows how to change all tabs or other delimiter, not just some.
Is there some built in command that could accomplish this?
I read https://www.mathworks.com/matlabcentral/answers/90662-how-to-replace-a-particular-string-in-text-file and am not sure if strrep and regexprep would work over all rows at once and preseve the carry/line return at the end of each line, or would I have to import the text file as an array an then use this over a cell array (the .txt file has both numbers and strings)? Also, I know an answer in the link prefers strrep becasue it is more efficient, but what is the difference?
Or would I have to use if statements and wild card charactors and re-write the text file?
Respuestas (1)
Image Analyst
el 18 de Abr. de 2020
0 votos
You could use fileread() and erase() then fprintf().
Categorías
Más información sobre Characters and Strings en Centro de ayuda y File Exchange.
Productos
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!