microsoft / devicescript

TypeScript for Tiny IoT Devices (ESP32, RP2040, ...)
https://microsoft.github.io/devicescript/
MIT License
3.29k stars 121 forks source link

Added string.replace() and .replaceAll() #698

Open xiboon opened 3 months ago

xiboon commented 3 months ago

finishes 1 task off of #683

xiboon commented 3 months ago

@microsoft-github-policy-service agree

xiboon commented 3 months ago

Could you add a test with replacing a string with multiple characters?

Added, also found a bug where replaceAll could loop infinitely so fixed that as well.

pelikhan commented 3 months ago

what if searchvalue equals replace value?

xiboon commented 3 months ago

i believe it shouldn't be an issue, that was part of the bug with replaceAll because if replaceValue contained searchValue it would just match against it forever. Now, after replacing a match it only searches for the index after the position of the replacement value so it can't possibly match against the thing it just replaced. Should i add that as a test just in case anyways?

pelikhan commented 3 months ago

What if you replace "" with ""?