Modifying

String replacement comprises two steps:

  1. Finding the part of the string to be replaced
  2. Replacing it with a given string.

We will cover multiple possible scenarios for each of these two steps in this section.

This section is organized as follows:

  • Replacing: Identify the substring to be replaced via a plain character sequence (the substring itself) or via a regular expression.
  • Substituting: Capture the part of the string to be replaced with its start and end character indices within the parent string.
  • Removing: A special case of replacement, where we identify a part of a string and replace it with an empty string ''.
  • Trimming: Another special case of replacement, where we remove leading and trailing empty space. We will also cover how to remove duplicate empty spaces within the string as well.
PYTHON
I/O