Unnecessary Censorship[1]. It’s easy: Read in a text file. Replace all 4 letter
ID: 3779905 • Letter: U
Question
Unnecessary Censorship[1]. It’s easy:
Read in a text file.
Replace all 4 letter words with "****".
Write the result back out to a new file.
For example, text.txt contains the text:
Hullabaloo, Caneck! Caneck!
Hullabaloo, Caneck! Caneck!
Good-bye to texas university
So long to the orange and the white
Good luck to dear old Texas Aggies
They are the boys that show the real old fight
"The eyes of Texas are upon you"
That is the song they sing so well
Invoke the censor function:
>> censor('text.txt');
The file text_censored.txt contains the censored text:
Hullabaloo, Caneck! Caneck!
Hullabaloo, Caneck! Caneck!
Good-bye to texas university
So **** to the orange and the white
**** **** to **** old Texas Aggies
**** are the **** **** **** the **** old fight
"The **** of Texas are **** you"
**** is the **** **** **** so ****
Note: the output file name is simply the input filename with _censored appended to the end.
>> in = 'text.txt';
>> out = [in(1:end-4) '_censored' in(end-3:end)]
out =
text_censored.txt
Challenge: Repeat, but read in a list of “banned” words from a file and replace each instance of a banned word in the text file with asterisks.
Explanation / Answer
censorship.m
========================================================
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.