How to insert a new line before a character in file?
Mostrar comentarios más antiguos
Hi, I have a file .txt format:
$text-text-text-text-text-text$text-text-text-text-text-text-text$text-text-text-textc....
I want to convert:
$text-text-text-text-text-text
$text-text-text-text-text-text-text
$text-text-text-text
$text-text-text-text
....
And don't have new line at beginning of text.
Thank you
Respuestas (2)
What is the wanted output? A cell string? A string? Another file?
% Perhaps: str = fileread('yourFile.txt');
str = '$text-text-text-text-text-text$text-text-text-text-text-text-text$text-text-text-text';
str = strrep(str, '$', [newline, '$']);
str(1) = [];
And to write this to a file:
writelines(str, 'outFile.txt');
str = '$text-text-text-text-text-text$text-text-text-text-text-text-text$text-text-text-textc'
s = strsplit(str,'$') ;
s'
3 comentarios
Khánh Tân
el 26 de Dic. de 2022
str = '$text-text-text-text-text-text$text-text-text-text-text-text-text$text-text-text-text' ;
s = strsplit(str,'$')' ;
s(1) = [] ;
for i = 1:length(s)
s{i} = ['$',s{i}] ;
end
s
Jan
el 26 de Dic. de 2022
You can omit the loop:
for i = 1:length(s)
s{i} = ['$',s{i}] ;
end
using:
s = strcat('$', s)
Categorías
Más información sobre Characters and Strings en Centro de ayuda y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!