Notice: This page requires JavaScript to function properly.
Please enable JavaScript in your browser settings or update your browser.
Aprende Challenge: String Manipulation Practice | Text Data Type
C++ Data Types

bookChallenge: String Manipulation Practice

replace.h

replace.h

copy
12
// replaces n characters starting from start with str2 str.replace(start, n, str2)
Tarea

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.

  1. First, find the position of the forbidden word in the comment using find method.
  2. Make sure the word is actually present in the comment by checking that the position is not -1 before attempting any replacement.
  3. 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 ("***").
  4. Return the modified comment.

Example

censorComment("This movie is stupid", "stupid")"This movie is ***"
censorComment("I hate bugs in code", "hate")"I *** bugs in code"
censorComment("What a nice day", "bad")"What a nice day"

Solución

solution.cpp

solution.cpp

¿Todo estuvo claro?

¿Cómo podemos mejorarlo?

¡Gracias por tus comentarios!

Sección 3. Capítulo 5
single

single

Pregunte a AI

expand

Pregunte a AI

ChatGPT

Pregunte lo que quiera o pruebe una de las preguntas sugeridas para comenzar nuestra charla

Suggested prompts:

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?

close

Awesome!

Completion rate improved to 4.35

bookChallenge: String Manipulation Practice

Desliza para mostrar el menú

replace.h

replace.h

copy
12
// replaces n characters starting from start with str2 str.replace(start, n, str2)
Tarea

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.

  1. First, find the position of the forbidden word in the comment using find method.
  2. Make sure the word is actually present in the comment by checking that the position is not -1 before attempting any replacement.
  3. 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 ("***").
  4. Return the modified comment.

Example

censorComment("This movie is stupid", "stupid")"This movie is ***"
censorComment("I hate bugs in code", "hate")"I *** bugs in code"
censorComment("What a nice day", "bad")"What a nice day"

Solución

solution.cpp

solution.cpp

Switch to desktopCambia al escritorio para practicar en el mundo realContinúe desde donde se encuentra utilizando una de las siguientes opciones
¿Todo estuvo claro?

¿Cómo podemos mejorarlo?

¡Gracias por tus comentarios!

Sección 3. Capítulo 5
single

single

some-alt