EzReplace - String replacer [CLOSED]

[!] This no longer is needed, and so you do not need to see this.

If you need to contain a whole lot of replaced strings with others, you should try EzReplace! It is quite a short module which I plan to focus on for now. DataStore Resource, my project I made too long ago will still get updates, just not as many as EzReplace’s.


What can it do?

It can replace strings with multiple changes, so if you wanted to, it could easily change a string with over 100 changes! (has been tested) . There is not much to say more than that!


How do I use it?

It only consists of 1 module which is easy to understand. This will be split up into 3 parts of this section.


Part 1 - AddNewChanging()

AddNewChanging is a function which adds a new string to be changed within another. Say we have a string saying “Riches favours the bold” and we add a changing like this:

local ezReplace = require(game.ReplicatedStorage.EzReplace) -- I suggest putting it in ReplicatedStorage

ezReplace.AddNewChanging("Riches", "Fortune")

Now, it adds a “Changing” which is an array of what to change and what to change it to so Riches, will turn into “Fortune”. But, this won’t suddenly create a whole entire string and print it / do what you need it to do yet.


Part 2 - Replace()

To replace a string, you want to use the function Replace which will return the changed string, let’s try it!

local ezReplace = require(game.ReplicatedStorage.EzReplace)

ezReplace.AddNewChanging("Riches", "Fortune")

local Replaced = ezReplace:Replace("Riches favours the bold.") -- This will turn into the changed sentence.

We can print our output Fortune favours the bold. by doing

local ezReplace = require(game.ReplicatedStorage.EzReplace)

ezReplace.AddNewChanging("Riches", "Fortune")

print(ezReplace:Replace("Riches favours the bold."))
Expected output

"Fortune favours the bold"


Part 3 - PrintChangings()

This will print everything which changes, we have our changing, where Riches turns into Fortune. So in the output it would print: “Riches → Fortune” and it will continue depending on how many changings you have created. Have fun with it!


Resource

EzReplace module


Outroduction

If you have any questions, feedback or need support with EzReplace, PM me! Please do not reply to the actual page instead of PMing me, as I prefer to keep the page clean.

1 Like

Im sorry, but why would i use it? Theres string.gsub() which is very easy to use.

1 Like

string.replace() doesn’t exist but string.gsub() does which does the exact same thing.

Not only that but gsub() allows for patterns which are very powerful. This module makes no sense when I can do the exact same thing without having to use an external tool:

print(string.gsub('Riches favours the bold.', 'Riches', 'Fortune'))
1 Like

Because, if you add multiple changings, and you have multiple changings in a long string then it could be useful. Also, I do not recall a function called string.replace. Also, this uses string.gsub() which, if you were doing a long string, you’d have to do:

print("The /player is /isonteam on the team /team":gsub("/player", player):gsub("/isonteam", ...)) continued continued.

Also, I requested you not to reply to the page.

You can do this easily:

string.gsub('The /player is /isonteam on the team /team', '%S+', {
  ['/player'] = 'Bob',
  ['/isonteam'] = 'probably',
  ['/team'] = 'Red'
}) --> Outputs: The Bob is probably on the team Red
2 Likes

My bad, but my point still stands tho.

1 Like

Very well, but this could still be helpful in keeping lines shorter is all I am saying, once again may you please not reply to the page, and PM me instead, like it says in the post?

Either way the resource is now shutting down. Thanks for the info.