Привет У меня есть текстовый файл, который имеетКак заменить определенные слова в текстовом файле на «*»?
Treadstone project
Jason Bourne is to neutralize Wombosi.
Nicky Parsons is the technician on the job
Bourne has shown interest in Marie Kreutz
Do not leak information about Blackbriar.
У меня есть массив ячеек с
words = {'treadstone','bourne','wombosi','parsons','blackbriar'}
Я полагаю, чтобы получить эту
********** project
Jason ****** is to neutralize *******.
Nicky ******* is the technician on the job
****** has shown interest in Marie Kreutz
Do not leak information about **********.
Но мой код печатает этот
********** project
Jason ****** is to neutralize Wombosi
Jason bourne is to neutralize *******.
Nicky ******* is the technician on the job
****** has shown interest in Marie Kreutz
Do not leak information about **********.
Это мой код:
while ischar(line)
if strcmp(line, '')
fprintf(output, line);
line = fgetl(fh);
end
[T N] = size(words);
for i = 1:N
mat = words{i}; %extreact the first word to comapre it to the text file
if strfind(lower(line), mat)
t = mat;
t(1:end) = '*'; %replace the word with *
ht = strfind(lower(line), mat); %find its location
hat = lower(line(ht));
line(ht) = hat; %replace the word with lower case
lalu = strrep(line, mat, t);
fprintf(output, '%s\n', lalu);
else
hat = 0;
end
end
line = fgetl(fh);
end
Любая помощь будет принята с благодарностью. Спасибо.
Ваш вкус фильмов это превосходно. Все шутя в сторону, я напишу ответ. – rayryeng
Вопрос. Вы целенаправленно смещены перед вашим текстом или являются символами '*' части исходного текста? Это очень запутанно. – rayryeng
Я просто смел перед моим текстом, чтобы его было легко читать. Я не мог смело смотреть на некоторые из них, как на проект **********. –