# Search for word and replace it with different words

**URL:** https://forum.kirupa.com/t/search-for-word-and-replace-it-with-different-words/208014
**Category:** Uncategorized
**Created:** [November 23, 2006, 11:46pm UTC](https://forum.kirupa.com/t/search-for-word-and-replace-it-with-different-words/208014 "2006-11-23T23:46:32Z")
**Posts on this page:** 1
**Page:** 1

<div class="post-metadata">

### Author: ![salvadore](https://avatars.discourse-cdn.com/v4/letter/s/f4b2a3/32.png) [@salvadore](https://forum.kirupa.com/u/salvadore)
#### Post date: [November 23, 2006, 11:46pm UTC](https://forum.kirupa.com/t/search-for-word-and-replace-it-with-different-words/208014/1 "2006-11-23T23:46:32Z")

</div>

Hi,

I found this handy function…

[FONT=Courier New][LEFT][COLOR=#0000ff]String[/COLOR].[COLOR=#0000ff]prototype[/COLOR].[COLOR=#000080]replace[/COLOR] = [COLOR=#000000] **function** [/COLOR]COLOR=#000000[/COLOR][COLOR=#000000]{[/COLOR]  
[COLOR=#0000ff]return[/COLOR] [COLOR=#0000ff]this[/COLOR].[COLOR=#0000ff]split[/COLOR]COLOR=#000000[/COLOR].[COLOR=#0000ff]join[/COLOR]COLOR=#000000[/COLOR].[COLOR=#0000ff]toString[/COLOR]COLOR=#000000[/COLOR];  
[COLOR=#000000]}[/COLOR]  
[COLOR=#808080]_// Example:_[/COLOR]  
foo = [COLOR=#ff0000]“Let’s replace all the e’s in this sentence with an o.”[/COLOR];  
[COLOR=#0000ff]trace[/COLOR]COLOR=#000000[/COLOR]  
[/LEFT]  
[/FONT]

How would I replace the first “e” with “a”, the second “e” with “b”, etc…

I guess with for loop. But I can’t figure it out…
