Some times during programming we are in hurry and not take care of these small issues like String Cannot be Zero Length. We should only take care about that when we perform replacing the old value, this value must have some text, otherwise we will get this same error of String Cannot be Zero Length. So here is the simple fix.
// Before
string.replace("", "any value");
// After
string.replace(" ", "any value");
Only difference is before we didn’t add some white spaces before but in next I added some white space and problem has been solved. Cheers 😉