README.md

December 4, 2022 ยท View on GitHub

Javascript Replace function

Description

How to use the String.replace function

More Info

Returns the string with the replaced characters

Submitted On
BySkunkPussie
LevelIntermediate
User Rating3.8 (19 globes from 5 users)
Compatibility
CategoryString Manipulation
WorldJava
Archive File

Source Code

// look for the word 'four' and replace with 'five' for all(g option) occurences
// String.replace(/text to find/options,replacement text)
sTMP = "see my four assed monkey, see my four assed monkey"
sTMP = sTMP.replace(/four/g,"five")
// outputted text looks like this
// sTMP = "see my five assed monkey, see my five assed monkey"
// without the (g) option it would look like this
sTMP = "see my four assed monkey, see my four assed monkey"
sTMP = sTMP.replace(/four/g,"five")
// outputted text looks like this
// sTMP = "see my five assed monkey, see my four assed monkey"