Advertisement
Java_Volume1 String Manipulation #99708

Javascript Replace function

How to use the String.replace function

AI

Resumen de IA: 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.

Código fuente
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"
Comentarios originales (3)
Recuperado de Wayback Machine