Advertisement
3_2004-2005 String Manipulation #145399

Javascript Replace function

How to use the String.replace function

AI

Ringkasan AI: This codebase represents a historical implementation of the logic described in the metadata. Our preservation engine analyzes the structure to provide context for modern developers.

Kode Sumber
original-source
// 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"
Komentar Asli (3)
Dipulihkan dari Wayback Machine