Challenge: String Manipulation Practice
replace.h
12// replaces n characters starting from start with str2 str.replace(start, n, str2)
Swipe to start coding
You are creating a content moderation system for user comments.
Your goal is to censor forbidden words by replacing them with "***".
The function censorComment takes a comment and a forbiddenWord as string.
- First, find the position of the forbidden word in the comment using
findmethod. - Make sure the word is actually present in the comment by checking that the position is not
-1before attempting any replacement. - Use
replace(start, n, str2)to censor the word:- First parameter: the starting position of the forbidden word (
pos). - Second parameter: the length of the forbidden word
forbiddenWord. - Third parameter: the string to replace the forbidden word (
"***").
- First parameter: the starting position of the forbidden word (
- Return the modified comment.
Solução
Obrigado pelo seu feedback!
single
Pergunte à IA
Pergunte à IA
Pergunte o que quiser ou experimente uma das perguntas sugeridas para iniciar nosso bate-papo
Can you explain what this video is about?
How can I add controls to this video?
Is there a way to make the video responsive for all devices?
Incrível!
Completion taxa melhorada para 4.35
Challenge: String Manipulation Practice
Deslize para mostrar o menu
replace.h
12// replaces n characters starting from start with str2 str.replace(start, n, str2)
Swipe to start coding
You are creating a content moderation system for user comments.
Your goal is to censor forbidden words by replacing them with "***".
The function censorComment takes a comment and a forbiddenWord as string.
- First, find the position of the forbidden word in the comment using
findmethod. - Make sure the word is actually present in the comment by checking that the position is not
-1before attempting any replacement. - Use
replace(start, n, str2)to censor the word:- First parameter: the starting position of the forbidden word (
pos). - Second parameter: the length of the forbidden word
forbiddenWord. - Third parameter: the string to replace the forbidden word (
"***").
- First parameter: the starting position of the forbidden word (
- Return the modified comment.
Solução
Obrigado pelo seu feedback!
single