How-to articles, tricks, and solutions about REPLACE

Finding and replacing elements in a list

Here is a Python code snippet that demonstrates how to find and replace elements in a list:

How do I replace a character in a string in Java?

To replace a character in a string in Java, you can use the String.replace(char oldChar, char newChar) method.

How to remove line breaks (no characters!) from the string?

There are a few different ways to remove line breaks from a string in PHP. Here are two options.

How to Replace a Word Inside a PHP String

Sometimes, it is necessary to replace a given word inside a string in PHP. Here, we will consider three helpful functions that help to carry out the task.

How to search and replace text in a file?

There are several ways to search and replace text in a file, depending on the programming language you are using.

Python string.replace regular expression

You can use the re module in Python to use regular expressions with the replace() method.

Remove specific characters from a string in Python

In Python, you can remove specific characters from a string by using the replace() method or using string slicing and concatenation.

Renaming column names in Pandas

To rename the column names of a Pandas DataFrame, you can use the DataFrame.rename() method.

Replace a character at a specific index in a string?

To replace a character at a specific index in a string in Java, you can use the substring() method of the java.lang.

search and replace value in PHP array

In PHP, you can use the array_map() function to search and replace values in an array.

Strip Leading and Trailing Spaces From Java String

To remove leading and trailing whitespace from a string in Java, you can use the trim method of the String class.