Replace all occurences within a string

This function is "the better" replace-function. Faster, easier and doesn't use Regex.


Libraries

Code Snippet
String.prototype.replaceAll = function(search, replacement) {
    return this.split(search).join(replacement);
}


Implementation

The snippet should be placed at the beginning of your first script. Here is a simple example how to use the snippet:<code>myString = "Tesst Hello abc 123 Tesst abc"; myString.replaceAll("Tesst", "Test");</code> The result is going to be <code>Test Hello abc 123 Test abc</code>





Comments
  • mode_editWrite a comment



  • forumComments




Embed Code

We provide special containers which include the full snippet and a link to this site. So for example when you make a tutorial and you are using code from this site, you can use one of the following snippet embeddings:

Load Preview Get Code Close Preview







    Share
    Rating
    thumb_up 1 thumb_down
    Author
    Thorolus

    I'm the head developer and co-founder of GlovilGames Studios (glovilgames.com) and other platforms GlovilGames created, like vsnippets.com, worth-calculator.net, python-obfuscator.com and some mobile apps and games.

    Tags
    Replace
    occurence
    string



    Informations

    posted on 2016-09-14 16:13:06

    viewed 102 times

    snippet's UUID is 57d95af2c0a4e

    Similar Snippets