Loading [MathJax]/jax/output/HTML-CSS/fonts/TeX/fontdata.js

Replace string method

The replace function, when attached to a string can replace a part of a string, with another specified string. 

The function is simple. Accepts two arguments. The first contains the string that we want to get rid off, and the second contains the string that is going to replace it.

Take a closer look to the example above, we replace the word 'negative' which lies inside the sentence string variable, with the word 'positive'. The replaced string is stored into a new string variable

In the end, line 5 prints: 'I have something positive to say here'

Replace Strings

Kostas Diakogiannis
Module by Kostas Diakogiannis, updated more than 1 year ago
No tags specified